A matrix is a transformation
A table of numbers that moves every point of the plane. Read it by its columns: they say where the two basic arrows land, and everything else follows.
1. The idea
A matrix is a table of numbers, and in machine learning it often just stores data, one row per example. But a matrix is also a machine: multiply it by a vector and out comes another vector. A 2 × 2 matrix moves every point of the plane, and you can watch it happen.
The way to read one is by its columns. The first column is where the arrow î = (1, 0) lands; the second is where ĵ = (0, 1) lands. Every other point follows, because (x, y) = x·î + y·ĵ and the matrix keeps that recipe: A(x, y) = x·(first column) + y·(second column), a linear combination of the columns, as in the last lesson. Grid lines stay straight, parallel and evenly spaced. That is what “linear” means.
Every dense layer in a network is one of these, in hundreds of dimensions: W𝐱 rotates, stretches and squashes its input before the activation function bends it. Stack two linear layers with nothing in between and you get just another matrix, W₂W₁, which is why that bend matters so much.
2. Try it: warp the plane
Try the example matrices, then move the four entries yourself. Watch where î and ĵ land: they are the columns. The shaded square shows what happens to area, which is the next lesson but one.
3. The math
4. The code (python)
import numpy as np
A = np.array([[1.0, 1.0], # a shear
[0.0, 1.0]])
print(A @ np.array([1.0, 0.0])) # [1. 0.]
print(A @ np.array([0.0, 1.0])) # [1. 1.]
print(A @ np.array([2.0, 3.0])) # [5. 3.]
t = np.radians(90) # a quarter turn
R = np.array([[np.cos(t), -np.sin(t)],
[np.sin(t), np.cos(t)]])
print((R @ np.array([1.0, 0.0])).round(3)) # [0. 1.]
W1 = np.array([[2.0, 0.0], [1.0, 1.0]])
W2 = np.array([[0.5, 1.0], [0.0, 3.0]])
x = np.array([1.0, 2.0])
print(W2 @ (W1 @ x), (W2 @ W1) @ x) # [4. 9.] [4. 9.]5. You’ll see this in
- Core Course chapter 8: XOR why a network needs the bend between linear layers
- The multi-layer perceptron in the catalog
- Reference notes: linear algebra coordinate transformations
6. Check yourself
Finished this chapter?
What changed in ML architectures this week
New models worth knowing, benchmark moves, and one architecture explained in plain words. Free, once a week, unsubscribe anytime.