liveBook · Manning

Tensor reshaping

As explained in Grokking Machine Learning

An array operation that changes the dimensions of stored values without changing their underlying elements.

Reshaping changes an array’s dimensions without changing its stored values. For neural-network input, a 28-by-28 MNIST image can be reshaped into a vector of 784 values by joining its rows. section 10.3

Flattening MNIST images

Use NumPy’s `reshape(-1, 28*28)` on the training and test images to turn each image into a 784-value vector. section 10.3

Figure 10.24 Before training the neural network, we preprocess the images and the labels in the following way. We shape the rectangular image into a long vector by concatenating the rows. We then convert each label into a vector of length 10 with only one non-zero entry in the position of the corresponding label.

Shows image rows concatenated into a long vector before neural-network training. section 10.3

How Grokking Machine Learning covers it

How deep it goes
Demonstrates flattening 28-by-28 images into 784-value vectors, without discussing reshaping internals.
Examples
Flattens MNIST images from 28-by-28 matrices into vectors of length 784.
What you can do after
Apply NumPy’s reshape function to convert MNIST image matrices into neural-network input vectors.
How it connects
Connects NumPy arrays and neural networks through MNIST image preprocessing.

Also explained in

Compare how 3 books explain tensor reshaping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning. The section links point to the parts of the book it draws on.