liveBook · Manning

Tensor reshaping

Tensor reshaping is an operation that changes a tensor’s dimensions or shape while preserving its elements and total number of values.

How 3 Manning books explain it

Grokking Machine Learning

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

How it is used
Prepares image arrays as vector inputs for a neural network.
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.

Read how Grokking Machine Learning explains tensor reshaping →

Inside Deep Learning: Math, Algorithms, Models

An operation that changes a tensor's shape without changing its total number of values, used here to turn a network output into an image-shaped tensor.

How it is used
Reframes tensor layouts for dataset inputs and for passing convolutional outputs into linear layers.
How deep it goes
Explains compatible dimensions, -1 inference, view tradeoffs, and flattening, but stops short of advanced memory-layout details.
Examples
Uses six-value tensors, X.reshape(-1,1), and nn.Flatten to demonstrate compatible shapes and feature collapsing.
What you can do after
Apply it via PyTorch to align dataset and network tensor shapes without changing the number of values.

Read how Inside Deep Learning: Math, Algorithms, Models explains tensor reshaping →

Grokking Statistics

A NumPy array operation that changes an array’s dimensions without changing its element values.

How it is used
Prepares one-variable NumPy input for scikit-learn logistic regression.
How deep it goes
Explains the required column shape and resulting error avoidance, but does not examine reshaping internals.
Examples
Uses hours-without-a-nap observations reshaped into a single input column.
What you can do after
Apply it via NumPy to format single-variable input for LogisticRegression.

Read how Grokking Statistics explains tensor reshaping →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.