torch.utils.data.DataLoader - why it adds a dimension
from torchvision import datasets, transforms
transform = transforms.Compose([transforms.ToTensor(),transforms.Normalize((0.5,), (0.5,)),])
trainset = datasets.MNIST('~/.pytorch/MNIST_data/', download=True, train=True, transform=transform)

trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)            # A
trainloader = torch.utils.data.DataLoader(trainset.train_data, batch_size=64, shuffle=True) # B

dataiter = iter(trainloader)     
images, labels = dataiter.next() # A
images         = dataiter.next() # B
images.shape

Why the code above, approach #A gives torch.Size([64, 1, 28, 28]) , while #B gives torch.Size([64, 28, 28])? Where does the second dimension with value 1 in #A come from?
Thank you in advance.

The second dimension describes the color channels which for grayscale is 1. RGB images would have 3 channels (red, green and blue) and would look something like 64, 3, W, H.
So when working with CNNs your data normally has to be in shape batchsize, channels, width, height therefore 64, 1, 28, 28 is correct.
