A tensor shape is the ordered list of integer sizes along its axes. A matrix with shape (2, 3) has two axes, containing two rows and three columns; a rank-3 tensor with shape (4, 3, 2) has three dimensions. Vectors have one size, such as (5), while scalars have an empty shape, (). section 2.2.5
MNIST image data
The MNIST training images have shape (60000, 28, 28): 60,000 grayscale images, each represented by a 28 × 28 matrix. The first dimension indexes samples, and the remaining dimensions describe each image. section 2.2.5
Common data layouts make the role of each dimension explicit:
- Vector data uses rank-2 tensors shaped (samples, features), such as (100000, 3) for people described by three attributes. section 2.2.8
- Sequence data uses rank-3 tensors shaped (samples, timesteps, features), with time conventionally occupying the second axis. section 2.2.8
- Images use rank-4 tensors shaped (samples, height, width, channels), while video uses rank-5 tensors shaped (samples, frames, height, width, channels). section 2.2.8
op_shape(train_images)
shape(60000, 28, 28)
Inspect a tensor’s shape directly with op_shape(train_images), which reports shape(60000, 28, 28). section 2.2.5
In Keras, layer output shapes help verify that a model’s dimensions change as intended. Declaring input_shape builds a Sequential model early, allowing summaries to display each layer’s output shape and supporting debugging of complex transformations such as convolutions. section 7.2.1




