I’m glad you like it here. 
You can find the documentations for tensor.numpy here 12.
It gives you a numpy array sharing the same storage as your tensor, which is really cheap and does not include a copy (at least if your tensor is already on the CPU).
PyTorch uses numpy internally as a dependency to provide this method, so you don’t need to manually import it.
The 0th element is used to get the “0th channel”, since dataset[7777] will return the sample as [channels, height, width]. In the case of MNIST images, we are using a single channel ([1, 28, 28]), so we just index it with 0. Otherwise matplotlib will be confused.
matplotlib uses a default colormap for single channel images (I think ‘viridis’ if I’m not mistaken).
This is supposed to give you better visual information about your matrix (smaller changes should be better visible than using a grayscale colormap).
However, since we are dealing with grayscale images, we can just force matplotlib to plot the matrix as we want.