liveBook · Manning

Tensor reshaping

Also called reshape

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
Prepares dataset samples and convolutional outputs for the tensor dimensions their next operation requires.
How deep it goes
Defines element-count preservation and inferred dimensions with -1; defers advanced details of why view can fail.
Examples
Shows six values reshaped to (3, 2), dataset arrays reshaped with (-1, 1), and convolution outputs flattened for linear layers.
What you can do after
Apply reshaping with PyTorch reshape to change tensor dimensions without changing element count, using -1 for an inferred dimension.

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 →

Also covered in

What to know first

Related concepts

Questions about tensor reshaping

What is tensor reshaping?

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

Which Manning books explain tensor reshaping?

Grokking Machine Learning, Inside Deep Learning: Math, Algorithms, Models and Grokking Statistics.

What should I know before learning tensor reshaping?

Manning books that teach tensor reshaping usually introduce array, inner product and tensor first.

What kinds of tensor reshaping are there?

Kinds of tensor reshaping include transposition.

What is tensor reshaping also called?

Tensor reshaping is also called reshape.

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.