Same Object, Different Shapes
Matrices come in flavors. Each flavor is just a constraint on the structure, but the constraints earn each their own name because they unlock specific powers.
| Type | Constraint | Why it's useful |
|---|---|---|
| Square | same number of rows and columns | only shape that has an inverse, determinant, eigenvalues |
| Rectangular | m ≠ n | changes dimensionality (e.g. project 1024-dim down to 256-dim) |
| Diagonal | zero off the diagonal | scaling per axis; multiplication is element-wise on diagonals |
| Identity | diagonal of 1s, zero elsewhere | multiplicative identity — |
| Zero | all zeros | additive identity — |
| Symmetric | often arises in correlation, distance, energy | |
| Sparse | mostly zeros | save memory, speed up multiplication when most cells are dead |
Why You Should Care
You'll meet most of these in the wild. Identity matrices show up in matrix inverse formulas. Diagonal matrices appear all through scaling and SVD. Symmetric matrices are the entire reason eigenvalue decomposition is well-behaved in many ML algorithms. Sparse matrices are how massive recommendation systems and graph neural networks fit in RAM at all.
import numpy as np
D = np.diag([2., 0.5, -1.]) v = np.array([10., 10., 10.])
print('D =') print(D) print('D @ v =', D @ v)