The Maths You Actually NeedLesson 12 of 76

Module 2 · Matrices, and what a layer really does

Shapes, batches, and the broadcasting rules

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 3 of 9 in this chapter

This chapter’s goalMultiply two matrices by hand and predict the output shape of any chain of layers, explain what the rank of a weight matrix costs and buys, and use singular values to justify replacing a 4096x4096 matrix with two thin ones and to state what that replacement gives up.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available
Three blocks of cells joined by arrows: a narrow column, a large square grid and a single tall bar.
A column of values entering a grid of weights and leaving as a shorter column, in that order: the shape change is what a layer does, and the grid’s rank decides whether two small matrices could stand in for it.

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

The batch dimension is a convenience, not a concept

Real code never multiplies one vector at a time. It stacks 32 or 256 examples into a batch and processes them together, because a GPU is a machine for doing the same arithmetic to many things at once. So every tensor grows a leading dimension, and the shapes you read look like (32, 128, 768): 32 examples, 128 token positions each, 768 features each.

The rule that keeps this simple is that matrix multiplication in NumPy and PyTorch acts on the last two dimensions and treats everything in front as batch. So (32, 128, 768) @ (768, 3072) gives (32, 128, 3072): the same 768 × 3072 weight matrix applied to each of the 32 × 128 = 4,096 individual vectors, with no loop written anywhere.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘Shapes, batches, and the broadcasting rules’, in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/shapes-broadcasting-and-batches (Accessed: 29 November 2026).