Module 2: Transformations
nn.Linear layer is literally a matrix multiplication. Every image transformation in Photoshop — rotate, scale, skew — is a matrix applied to pixel coordinates.Last lesson you saw that a linear transformation is fully determined by where ^ and ^ land. A matrix is just the most compact way to write that down.
A 2×2 matrix stores exactly two things: the new home of ^ in the first column, and the new home of ^ in the second column.
The rotation by 90° matrix is a good example: ^=[1,0] lands at [0,1] (straight up), and ^=[0,1] lands at [−1,0] (pointing left):
To transform a vector [x, y], use the matrix columns as scaled versions of where the basis vectors went:
It's a linear combination — x copies of where î landed, plus y copies of where ĵ landed. That's matrix-vector multiplication, fully explained.
Below the matrix editor you'll see a determinant value. This number measures how much the transformation scales area. Determinant 2 means areas double. Determinant −1 means areas stay the same but orientation flips. Determinant 0 means the transformation collapses the entire plane down to a line — or even a point.
We'll spend a full module on determinants. For now, just notice how it changes as you edit the matrix.
import numpy as np
# Rotation by 90°
M = np.array([[0, -1],
[1, 0]])
v = np.array([3, 1])
print(M @ v) # [-1 3] — matrix-vector multiplyThe @ operator is matrix multiplication in NumPy.M @ v applies the transformation M to the vector v.