Key ideas
Objects and shapes. A vector is a 1-D array (one example's features), a matrix a 2-D array (a dense layer's weights), a tensor any -D array. With one example per row, a mini-batch of examples with features is . A product needs matching inner sizes: , and entry is row of dotted with column of 1. A batch of 32 examples with 10 features times a weight matrix gives : one row of 64 outputs per example.
Norms1: (Manhattan, city-block distance), , . Every norm satisfies and the triangle inequality — equality is not guaranteed. Among the -norms only comes from an inner product, since only it satisfies the parallelogram law7. is the walking distance on a grid (no diagonals).
Dot products and angles2: ; orthogonal means ; cosine similarity ignores length. For unit vectors . The closest point to on the line through a unit vector is . Entry of is the dot product of rows and — a cosine only if the rows are normalised.
Rank, null space, invertibility. Rank = number of linearly independent columns 2; rank + nullity = number of columns4. The solutions of form a subspace (the null space) of dimension : sums and multiples of solutions are solutions, and a nullity of 2 or more means they are not all multiples of one vector. For a square these are equivalent: invertible, , full rank, columns independent, null space , uniquely solvable for every , 0 not an eigenvalue2. Pairwise independence of columns is weaker and not enough. A column times a row () has rank 1, so its determinant is 0; a set of vectors containing is always dependent. For , .
Linear maps and subspaces. A linear map is fixed by its values on a basis: write the new input as a combination of inputs you know and combine their images the same way. For a linear map , (the rank theorem again)4. Two subspaces of a space satisfy , because .
Determinant = signed factor by which scales area/volume2; for , . , . If , densities rescale: .
Eigenvalues. , ; eigenvalues are roots of . Then , — read them off the characteristic polynomial: its constant term is and the coefficient of is . , , keep the eigenvectors with eigenvalues , , 3. Symmetric matrices have real eigenvalues and orthogonal eigenvectors, 3. Similar matrices () share eigenvalues, trace and determinant. A projection () has eigenvalues 0 and 1 only, is diagonalizable, and its trace equals its rank. and are always symmetric; maps orthogonal to orthogonal vectors exactly when its columns are orthogonal, i.e. is diagonal.
Power iteration. Repeatedly multiplying a random vector by (and normalising) aligns it with the eigenvector of the largest ; the other components shrink like 3.
Singular values. ; the singular values are the square roots of the eigenvalues of , and the spectral norm is the largest one6. Power iteration on therefore estimates from below: a ratio can never exceed .
Random matrices. Take a matrix with independent entries of mean 0 and variance 1 (e.g. standard normal). Its largest is about (circular law)3, but its spectral norm is as (Bai–Yin law, needs a finite fourth moment); for Gaussian entries for every 8. So a matrix of size-1 entries stretches some vector by about — why initial weights are scaled by .
Cost of products. costs multiplications. Matrix multiplication is associative, so choose the parenthesisation that keeps intermediate results small5. For a tall (), costs but costs , because it builds an intermediate.
Einsum. Repeated indices are summed: , ; in code
torch.einsum('ij,jk->ik', A, B)2.
Formulas
Worked example
: gives with eigenvectors and . Check: trace , determinant , so triples areas. has eigenvalues and ; power iteration on approaches , with the error shrinking by per step.
Chain cost with , , : costs ; costs .
In code
import numpy as np
A = np.array([[2.0, 1.0], [1.0, 2.0]])
print(np.linalg.eigvalsh(A)) # [1. 3.]
print(np.trace(A), round(np.linalg.det(A), 6)) # 4.0 3.0
B = np.array([[1.0, 2.0], [0.0, 2.0]])
print(np.linalg.svd(B, compute_uv=False)) # [2.92080963 0.68474165]
rng = np.random.default_rng(0)
d = 1000
G = rng.standard_normal((d, d))
print(round(np.linalg.norm(G, 2) / np.sqrt(d), 3)) # 1.998
print(round(np.abs(np.linalg.eigvals(G)).max() / np.sqrt(d), 3)) # 1.014
Common pitfalls
- Shapes: with examples as rows, is (batch × features), not the transpose.
- is false in general; only the triangle inequality holds1.
- Determinant 0 ⇔ not invertible; a large determinant does not mean "well-conditioned".
- Eigenvectors are shared by , , , — the eigenvalues change3.
- , and can be negative; but .
- Singular values ≠ eigenvalues unless is symmetric positive semidefinite6.
- Matrix products are associative but not commutative; order of evaluation changes the cost, not the result5.
References
- Dive into Deep Learning — Sec. 2.3.10 Matrix–Matrix Multiplication; Sec. 2.3.11 Norms
- Dive into Deep Learning — Sec. 22.1.2 Dot Products and Angles; 22.1.6 Rank; 22.1.7 Invertibility; 22.1.8 Determinant; 22.1.9 Tensors and Common Linear Algebra Operations
- Dive into Deep Learning — Sec. 22.2.3 Operations on Eigendecompositions; 22.2.4 Eigendecompositions of Symmetric Matrices; 22.2.6 A Useful Application — The Growth of Iterated Maps; 22.2.7 Discussion
- Margalit & Rabinoff, Interactive Linear Algebra — Sec. 2.9 The Rank Theorem
- Wikipedia: Matrix chain multiplication — Introduction
- Wikipedia: Singular value decomposition — SVD and spectral decomposition (Relation to eigenvalue decomposition); Norms (Ky Fan norms)
- Vershynin, Introduction to the non-asymptotic analysis of random matrices (2010), arXiv:1011.3027 — Sec. 5.3.1 Limit laws and Gaussian matrices (Theorem 5.31 Bai–Yin's law; Theorem 5.32 Gordon's theorem)
- Wikipedia: Parallelogram law — Normed vector spaces satisfying the parallelogram law