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.
100Math for the Metal (arithmetic & shapes)Lesson 1 of 4ShowHide
Chapter 1 of 2 in Math for ML/AI Workloads
- What Is a Tensor? — A Multidimensional ArrayYou're here
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:
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 is | shape | rank | each value is |
|---|---|---|---|
| one grayscale pixel | () | 0 · scalar | a brightness, 0 (black) → 255 (white) |
| a row of pixels | (width,) | 1 · vector | one brightness each |
| a grayscale photo | (height, width) | 2 · matrix | a grid of brightnesses |
| a color photo | (height, width, 3) | 3 · 3-tensor | three numbers per pixel — R, G, B |
| a batch / a video's frames | (n, height, width, 3) | 4 · 4-tensor | the 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:
Step through the ranks and watch the structure grow:
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):
| rank | shape | elements | bytes |
|---|---|---|---|
| 1 | (4096,) | 4 K | 8 KiB |
| 2 | (4096, 4096) | 16 M | 32 MiB |
| 3 | (4096, 4096, 4096) | 69 B | 128 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
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.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.
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
What is a tensor, in one line?
Check yourself
An activation tensor has shape [batch, seq, hidden]. What is its rank?
Go deeper
What's a Tensor? — Dan Fleisch (12 min) →
The clearest geometric intuition for where the word 'tensor' comes from — built from arrows, shadows, and basis vectors with household objects. It teaches the physics tensor (coordinate-system machinery we don't need to operate chips), so treat it as optional origin-of-the-word; for operations, a tensor is just a multidimensional array.
NotebookWhat Is a Tensor? — see it in numpy · open in NotebookLM →
Reads rank and shape straight off numpy arrays, computes the footprint formula, and charts the rank → memory blow-up (rank 3 punches through a chip's HBM). Pure numpy, runs on CPU.
Reason about rank and the memory bill
An activation tensor has shape [batch=8, seq=8192, hidden=4096] in bf16. State its rank, compute its footprint in bytes, then explain why doubling the sequence length and why adding one more dimension each affect HBM differently. Tie it back to why a longer-context job can OOM when a shorter one fit on the same chip.