Skip to content

1.1 Vectors and matrices as transformations

ready≈ 10.5 hoursNeeds: 0.2Unlocks: 1.2, 1.3, 2.2
  1. 1 Learn
  2. 2 Bridge & derive
  3. 3 Explore (Matrix transformer)
  4. 4 Do
  5. 5 Check

Read a matrix A\mathbf{A}matrixA matrix, written bold upper-case. A_{ij} is row i, column j.Introduced in 1.1 Vectors and matrices as transformations. UDL writes weights as Ω (Omega) and biases as β; we use W and b. as a function that moves space, not as a grid of numbers. A linear map is fixed by where it sends the basis vectors, and those images are the matrix’s columns. So Ax=x1a1+x2a2\mathbf{A}\mathbf{x} = x_1\mathbf{a}_1 + x_2\mathbf{a}_2 is “take x1x_1 of the first column plus x2x_2 of the second” (3Blue1Brown, ch. 3; MML §2.7). Multiplying matrices composes the maps: AB\mathbf{A}\mathbf{B} means “do B\mathbf{B}, then A\mathbf{A}”, which is why order matters (3Blue1Brown, ch. 4).

The determinant det⁡(A)\det(\mathbf{A})determinantSigned factor by which A scales areas (volumes). Zero means A squashes space flat.Introduced in 1.1 Vectors and matrices as transformations. is the factor by which a map scales area (volume in 3-D). It is negative when the map flips orientation, and zero when it squashes space onto a line, so no inverse exists (3Blue1Brown, ch. 6; MML §4.1).

The dot product u⊤x\mathbf{u}^\top\mathbf{x} (A⊤\mathbf{A}^\toptransposeRows become columns: (Aᵀ)_{ij} = A_{ji}. xᵀy is the dot product.Introduced in 1.1 Vectors and matrices as transformations. is the transpose) measures how much x\mathbf{x} points along u\mathbf{u}. That gives the projection onto the line through u\mathbf{u}: u⊤xu⊤uu\frac{\mathbf{u}^\top\mathbf{x}}{\mathbf{u}^\top\mathbf{u}}\mathbf{u} (3Blue1Brown, ch. 9; MML §3.8.1). Projecting onto the span of several vectors (the columns of B\mathbf{B}) is the idea behind least squares in module 2.2. The derivation below is the one to own (MML §3.8.2).

Why care? Every layer of a neural network is a matrix followed by a simple nonlinearity (UDL §4.4), and attention (4.4) is built from dot products and weighted sums of columns (UDL §12.2).

Projection onto a subspacestep 1 of 5
  1. p=Bλfor some λ∈Rk\mathbf{p} = \mathbf{B}\boldsymbol{\lambda} \quad\text{for some } \boldsymbol{\lambda} \in \mathbb{R}^k

★ Matrix transformer

Matrices as maps, determinant as area, eigenvectors as directions that don't turn

Static view on small screens. Open this page on a laptop to interact.

λ1=1.00λ2=1.00Mvv
M = [[1.00, 0.00], [0.00, 1.00]] det M = 1.00 λ = 1.00, 1.00 Mv = (1.50, 1.00)

Drag the blue and orange dots: they are the matrix's columns, where i-hat and j-hat land. The shaded square is the image of the unit square, so its area is |det M|. Drag v onto a dashed eigenvector line and Mv stays on that line, scaled by λ.

Matrix columns: i-hat lands at (1.00, 0.00), j-hat at (0.00, 1.00). Determinant 1.00. Eigenvalues 1.00 and 1.00.

A 2×2 matrix shown as a deformed grid. The blue and orange arrows are the matrix’s columns, the images of the basis vectors. The shaded parallelogram is the image of the unit square, whose area is the determinant. Dashed lines are real eigenvector directions. Keyboard: Tab to a dot, then arrow keys move it (Shift for bigger steps).

Try these: make the determinant 0, then negative. Find a matrix with no dashed lines (a rotation). Set the columns to (2, 1) and (1, 2), then drag v onto a dashed line.

A = np.array([[2.0, 1.0], [1.0, 2.0]])
B = np.array([[0.0, -1.0], [1.0, 0.0]])   # rotate 90°
print(A @ B)
print(B @ A)        # order matters
np.linalg.det(A @ B), np.linalg.det(A) * np.linalg.det(B)

Tab indents · Esc then Tab leaves the editor · Shift+Enter runs

Implement matrix multiplication with loops, matrix-vector products as column combinations, rotations, the 2×2 determinant, and both projections. The tests compare against NumPy and check the geometry: residuals are orthogonal, and projecting twice changes nothing.

Matmul and projections stubs/m1_1_linalg.py

Loading starter file…

Prefer your own editor? Edit exercises/stubs/m1_1_linalg.py and run mlc check 1.1. The tests are identical; import the results on the progress page.

Hints · matmul 0/3 revealed
Hints · project_onto_subspace 0/3 revealed

Locally: mlc check 1.1.

1. A 2×2 matrix sends i-hat to (2, 0) and j-hat to (1, 3). What is the matrix?
2. det(A) = −2. What does A do to the unit square?
3. Why solve BᵀBλ = Bᵀx instead of computing (BᵀB)⁻¹?
4. p is the projection of x onto span(B). Which statement is always true?
  • not yet: All tests pass (0/?)
  • not yet: Checkpoint quiz ≥ 80%
Finish the items above first.
Learner log: time spent and points of confusion

Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.