Tensor reshaping
Tensor reshaping is an operation that changes a tensor’s dimensions or shape while preserving its elements and total number of values.
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.
Related concepts
- transpositionincludes · Transposition is an operation that exchanges a matrix’s rows and columns or, more generally, reorders the axes of a tensor without changing its values.
- tensoruses · A tensor is a multidimensional, array-like structure of values indexed along zero or more dimensions and used for numerical computation.
- viewequivalent to · A view is an alternate representation or access interface for data derived from or backed by underlying storage without necessarily creating an independent copy.
- vectorproduces · A vector is an ordered, indexed sequence of elements, often numerical, represented as a mathematical quantity or a computational collection.
- grayscale imageproduces · A grayscale image represents each pixel with a single achromatic intensity value rather than separate color components.
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.


