A digital image can be represented as a tensor of pixel values. In the MNIST example, each handwritten digit is stored as a 28 × 28 image, flattened into a 784-element PyTorch tensor for model processing. Each value represents a pixel’s signal: 0 denotes the background, while larger values indicate brighter regions. section 13.2.2
Working with image data commonly involves these transformations:
- Convert images to PyTorch tensors and normalize their pixel values. section 13.2.4
- Flatten two-dimensional images into feature vectors when using models that expect tabular inputs. section 13.2.2
- Reshape vectors back into grids and visualize them as heat maps. section 13.2.2
- Treat pixel similarity cautiously: images with similar pixel patterns can represent different digits, while differently arranged pixels can share a label. section 13.2.3
MNIST image representation
A handwritten digit is loaded with torchvision, converted to a tensor, and stored as a flattened vector. Reshaping the first vector to 28 × 28 and displaying it with imshow reveals the original digit as a heat map. section 13.2.2 section 13.2.4















