liveBook · Manning

Tensor

As explained in Grokking AI Algorithms, Second Edition

A tensor is a multidimensional numerical array used to represent data and intermediate computations in machine-learning models.

A tensor is a multidimensional structure for numerical values. Think of it as a container whose shape tells you how its values are arranged. Neural networks use tensors for inputs, weights, and outputs so they can transform whole layers at once instead of processing each node and connection separately. section 9.13

Start with familiar shapes:

  • A scalar is one number: a 0D tensor, such as 5. section 9.13
  • A vector is a 1D array, such as [2.1, -0.3, 4.7]; a matrix is a 2D grid. section 9.13
  • A color image can be a 3D tensor with height, width, and color channels. A batch of images adds a fourth dimension. section 9.13

Reading an image tensor’s shape

An 8×8 grayscale image has one channel and can be represented as a matrix. An 8×8 color image has three channels, giving an 8×8×3 tensor. The extra dimension keeps the red, green, and blue values associated with each pixel. section 12.14

Combining feature maps

A U-Net decoder combines an 8×8×8 tensor from an earlier encoder layer with an upsampled 16×8×8 tensor. Stacking their channels produces a 24×8×8 tensor: the spatial dimensions stay 8×8, while the channel counts add. This gives the decoder both fine image detail and deeper features. section 12.19

Check what each dimension means before combining tensors. The color-image example writes channels last (8×8×3), while the decoder example writes channels first (24×8×8); the numbers alone do not identify the axes. section 12.14 section 12.19

12.42 How skip-connection feature maps are combined with the upsampled feature maps
12_42

See how a skip connection combines feature maps with upsampled feature maps in the decoder. section 12.19

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines tensors through dimensions and works through image shapes and decoder concatenation; defers tensor algebra details.
Examples
Uses numerical scalars and vectors, color-image and image-batch shapes, and a 24×8×8 decoder tensor formed by concatenation.
What it assumes
Introduces scalars, vectors, and matrices from simple numerical examples while assuming familiarity with arrays and image pixels.
What you can do after
Evaluate/understand tensor shapes in image models and how concatenating feature maps changes channel count.
How it connects
Connects tensors to scalars, vectors, matrices, artificial neural networks, convolutional layers, and skip connections.

Also explained in

Compare how 7 books explain tensor →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.