Lesson 1.2foundation3 h⚡ live demo

Matrices as transformations

A matrix is what happens to a vector

A matrix is the thing that happens to a vector. Every linear layer, every attention-score matrix, every covariance and every rotation of an image is a matrix acting on vectors, and "training" mostly means adjusting the entries of such matrices. This lesson teaches you to see Ax\mathbf{A}\mathbf{x} as a transformation, matrix multiplication as composition, the determinant as a volume scale and the inverse as undoing — and then reads the linear layer XW⊤+b\mathbf{X}\mathbf{W}^\top+\mathbf{b} of 4.1 From perceptron to MLP; universal approximation and the attention scores QK⊤\mathbf{Q}\mathbf{K}^\top of 7.2 Scaled dot-product and multi-head attention, fully derived in exactly those terms.

You'll be able to

  • Compute matrix–vector and matrix–matrix products in both the column and the row picture, and track shapes
  • Interpret determinant, inverse, rank, column space and null space geometrically
  • Recognize the special matrices (diagonal, orthogonal, symmetric, positive definite, projection) and what each does
  • Read a batched linear layer as a matrix product and count its parameters and floating-point operations

Key ideas

  1. Ax is a linear combination of the columns (column picture) and a stack of dot products with the rows (row picture); the columns are where the basis vectors land.
  2. Matrix multiplication is composition of transformations, read right to left: associative, not commutative, shapes (m×n)(n×p) = m×p.
  3. Determinant = signed area/volume scale factor; det = 0 ⇔ space is squashed ⇔ not invertible; det(AB) = det A · det B.
Show 4 more key ideas
  1. Column space = reachable outputs (dimension = rank); null space = inputs squashed to zero; rank + nullity = n.
  2. Orthogonal matrices preserve lengths and angles; symmetric PSD matrices are bowls (covariances, Hessians at minima).
  3. A batched linear layer is Z = XWᵀ + b with kd + k parameters and about 2ndk flops; attention scores QKᵀ are the same operation.
  4. Solve linear systems with a solver, never with an explicit inverse.

Suggested path through this lesson