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
- 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.
Also covered in
- Build AI Drug Discovery PipelinesIn early access (MEAP)
- Julia as a Second Language
- Learn Generative AI with PyTorch
- Deep Learning with R, Third Edition
- Deep Learning with Python, Third Edition
What to know first
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- inner productAn inner product is a scalar-valued operation on two vectors that generalizes the dot product, which for real coordinate vectors is the sum of products of corresponding components.
- tensorA tensor is a multidimensional numerical array whose values are arranged along indexed dimensions and can be manipulated through mathematical computation.
Related concepts
- transpositionincludes · Transposition is an operation that exchanges a matrix’s rows and columns or, more generally, permutes the axes of a multidimensional array.
- tensoruses · A tensor is a multidimensional numerical array whose values are arranged along indexed dimensions and can be manipulated through mathematical computation.
- viewequivalent to · A view is a representation or access interface that presents selected, transformed, or derived information from underlying data or state.
- grayscale imageproduces · A grayscale image represents each pixel using an intensity value, conveying brightness without encoding chromatic color information.
- vectorproduces · A vector is an ordered sequence of elements treated as a single object, with its size fixed or resizable depending on the context.
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.


