Back to paths

What Is a Tensor? — A Multidimensional Array

Before precision or shapes can make sense, one word needs nailing down — tensor. To the hardware it is nothing exotic; it is a multidimensional array of numbers stored as a flat row in memory. This builds the idea from a geometric arrow (its components are shadows on the axes) up to rank, and shows why each dimension you add multiplies the memory bill. For infra engineers, no calculus.

beginner~12 min#math-infra#fundamentals#memory
100Math for the Metal (arithmetic & shapes)Lesson 1 of 4Show

The one-line summary

Every later lesson — precision, shapes, sharding — leans on one word: tensor. It sounds exotic. It isn't. To the hardware, a is just a multidimensional array of numbers — a flat row of values in memory, plus a shape that says how to read them. A single number, a list, a grid, a cube of numbers: all tensors, differing only in how many dimensions they have. Get that, and "the model is just tensors flowing through chips" stops being a slogan and becomes something you can reason about.

From an arrow to an array — the shadow trick

So where do the numbers come from? Start with something physical: an arrow in space (a direction with a length). You can't store an arrow — but you can measure its shadow on each axis. Those shadow lengths are the arrow's components, and that list of components — [x, y, z] — is the array the computer keeps.

Drag the arrow below and watch geometry turn into a stored array:

Simulation: vector-basis-explorer

The shadow on an axis is called a ; the little length-1 rulers (x̂, ŷ, ẑ — the caret ˆ just means "length exactly 1 along that axis") are the , the agreed unit that makes the numbers mean a real direction.

You'll essentially never touch basis vectors operating ML systems — but they're why a flat list of numbers can stand in for a real object, which is the same reason a wrong shape, not a wrong value, is what usually breaks a run.

Rank — how many dimensions

The one number that classifies a tensor is its : how many dimensions it has, i.e. how many indices you need to reach a single value.

  • rank 0 — a , one number, shape ().
  • rank 1 — a , a list, shape (n,) — the [x, y, z] above.
  • rank 2 — a , a grid, shape (rows, cols).
  • rank 3+ — a cube and beyond, like [batch, seq, hidden].

A tensor you already know — a digital image

Forget arrows for a second. A digital image is a tensor, and it shows you every rank at once:

what it isshaperankeach value is
one grayscale pixel()0 · scalara brightness, 0 (black) → 255 (white)
a row of pixels(width,)1 · vectorone brightness each
a grayscale photo(height, width)2 · matrixa grid of brightnesses
a color photo(height, width, 3)3 · 3-tensorthree numbers per pixel — R, G, B
a batch / a video's frames(n, height, width, 3)4 · 4-tensorthe same, stacked

A grayscale photo is literally a grid of brightness numbers — one per pixel. Now make it color: you don't get a new picture, you get a third dimension — a new axis called channels. The same grid, but three values deep — how much red, green, and blue sit at each pixel. That channels axis is exactly the jump from a matrix to a rank-3 tensor. Stack a batch of photos (or a video's frames) and you've added a fourth.

Walk an image up the ranks yourself — one pixel, a row, a grayscale grid, then color (the +RGB channels dimension), then a stack of frames — and watch the stored array grow right alongside it:

Simulation: image-tensor-explorer

Step through the ranks and watch the structure grow:

Simulation: tensor-rank-explorer

Why rank is the scariest word in a memory budget

Here's the operational punchline. Each dimension you add doesn't add to the size — it multiplies it. The number of elements is the product of the dimensions, so growth is multiplicative, not additive.

Make it concrete at model scale — every dimension 4096 wide, in bf16 (2 bytes each):

rankshapeelementsbytes
1(4096,)4 K8 KiB
2(4096, 4096)16 M32 MiB
3(4096, 4096, 4096)69 B128 GiB

One extra dimension took the same kind of data from 32 MiB to 128 GiB — past a single accelerator's (today's high-end parts hold ~80–140 GB). Nothing changed but the rank.

Where the word comes from (optional, and lovely)

If you want the deeper geometric story — why we even say "tensor," and how basis vectors carry it — Dan Fleisch explains it in twelve minutes with blocks and a desk lamp. It's the physics view (which adds coordinate-system machinery we don't need to operate chips), but it's the clearest intuition for the shadow trick you used above.

For operating ML systems, the array definition is all you need: a tensor is a multidimensional array, and its rank is how many dimensions it has.

Why this matters

  • It's the vocabulary for everything else. Shapes, padding, precision, sharding — all of it is "what's the rank and the shape, and how many bytes does that come to."
  • Rank drives the memory bill. Sizing HBM, predicting an OOM, reading why a longer sequence blows up — all start with "how many dimensions, each how big, times the dtype."
  • The chip stores a flat array. No arrows, no geometry at runtime — just a row of numbers and a shape. That's why a wrong shape, not a wrong value, is what usually breaks a run — and the next lesson, on tensor shapes, shows how to compute that footprint before a job ever starts.

Put it together

Steps
  1. Read a shape as a rank

    Given [batch, seq, hidden], say the rank out loud and explain what "one index per dimension" means for reaching a single number.

  2. Turn geometry into an array

    In the first sim, set the arrow flat on the floor, then lift it with Z. Explain what "adding a dimension" did to the list of numbers the computer stores.

  3. Scare yourself with rank

    In the second sim, step rank 1 → 2 → 3 at model scale. State, in one sentence, why the jump from 32 MiB to 128 GiB happens — and what that predicts about activation tensors in a real run.

Review

Flashcards1 / 5

What is a tensor, in one line?

Check yourself

Quick exam1 / 3 · 0 correct

An activation tensor has shape [batch, seq, hidden]. What is its rank?

Go deeper

Your notes on this lesson