The target label appearing on image grid is dfferent from the label being printed

I am trying to show the images along with respective labels being loaded in the data loader batch. Labels are: 0,1,2,3. However, the labels displayed on the top image are different from the labels that I simply print using the print command. Should not be both these labels same?

def imshow(inp, title=None):
    """Imshow for Tensor."""
    inp = inp.numpy().transpose((1, 2, 0))
    plt.imshow(inp)
    if title is not None:
         plt.title(title)

# Get a batch of training data
image, label = next(iter(train_loader))
print(label) # prinitng respective labels 
# Make a grid from batch
out = torchvision.utils.make_grid(image)
imshow(out, title=[label[x] for x in label])

Below is the screenshot of printed labels and labels being displayed as titles on respective images.

The different outputs are expected, since you are indexing label with itself:

label = torch.tensor([1, 3, 0, 1])
print(label)
> tensor([1, 3, 0, 1])
print([label[x] for x in label])
> [tensor(3), tensor(1), tensor(1), tensor(3)]

I did not get your point. Since the label of the 4 images respectively is tensor([1, 3, 0, 1]). So, how indexing through label is changing the output? lable[1]-> 1, lable[2]->3, lable[3]->0, label[4]-> 1. Should not be this output. Can you please explain?

The list comprehension uses:

label = torch.tensor([1, 3, 0, 1])
# which equals to
label[0] = 1
label[1] = 3
label[2] = 0
label[3] = 1

# your list comprehension uses the label itself to index into it
[label[x] for x in label]
== [label[1], label[3], label[0], label[1]]
== [3, 1, 1, 3]