First PrinciplesStart anywhere. Prove it, then move on.

Rung 29

Matrices as transformations

A matrix is not a grid of numbers. It is something that happens to space.

Best attempted after 28. Vectors. Nothing stops you trying this now — the gate will tell you if you were right.

The gate

Take a 2×2 matrix and apply it by hand to the four corners of the unit square. Draw the result. Then verify with code. Then, working backwards, construct one matrix that rotates by 90 degrees and one that shears, and predict the sign and size of each determinant before computing it.

Nobody checks this but you. Do it honestly and the rungs above hold; do it loosely and they will not, somewhere further up where the cause is much harder to find.

A matrix looks like a grid of numbers, which is the least useful way to think about it. A matrix is a transformation: feed it a vector, get back a different vector, and the same rule applies to every vector in the space at once.

The single fact that makes matrices readable: the columns of a matrix are where the basis vectors land. Column one is the image of (1, 0). Column two is the image of (0, 1). Everything else follows, because every vector is a combination of those two and the transformation preserves combinations.

Why this is on the ladder

Because a layer of a neural network is a matrix multiply followed by a bend. At rung 44 you will write that multiply by hand, and if a matrix is a grid of numbers to you then the code is bookkeeping. If it is a transformation, the code says something: this layer reshapes the space the data lives in.

Do this

Take [[2, 1], [0, 3]]. Read the columns: (1,0) goes to (2,0), and (0,1) goes to (1,3). Now apply it to the unit square's corners — (0,0), (1,0), (1,1), (0,1) — by hand, and draw both the square and its image.

Verify with code. Then measure the area of the image. Compare it to the determinant, 2·3 − 1·0 = 6. That is not a coincidence: the determinant is the factor by which area is scaled.

Now work backwards. Build a matrix that rotates 90 degrees counter-clockwise by asking only "where should (1,0) and (0,1) end up?" Build a shear the same way. Before computing either determinant, predict it: a rotation changes no area, so 1; a shear slides without stretching, so also 1.

Then build a matrix that squashes the plane onto a line, and predict a determinant of zero before you check.

Where people get stuck

Memorising the multiplication procedure without the picture. The procedure is easy and tells you nothing. Ask instead where the basis vectors go, and matrix multiplication becomes "do this transformation, then that one" — which is also why order matters and AB ≠ BA.

The determinant's sign also puzzles people. Negative means the transformation flipped the space over, turning it inside out. Draw a lettered shape and watch it come back mirrored.

Reading