How to find Shape and columns for dataloader

In the below code , I see that we are loading the data into the variable “trainloader” and iterating through the same. In the below example, the code assumes that there are two columns of data , images & labels respectively. How do I check the shape and column headers in the data “trainloader” . Any help is much appreciated.

Download and load the training data

trainset = datasets.MNIST('~/.pytorch/MNIST_data/', download=True, train=True, transform=transform)
trainloader =, batch_size=64, shuffle=True)

dataiter = iter(trainloader)
images, labels =

Column headers are not necessary information, as you can name them whatever you wish (in this case, images, labels).

I have more often seen the train loader being iterated as such:

for i, (images, labels) in enumerate(trainloader):

In such a case, you could get the number of items returned by the train loader with n_columns = len(trainloader[0]).

1 Like