Linear Algebra Basics Cheat Sheet

Essential linear algebra for data science and ML: vectors, matrices, eigenvalues, SVD, dot products, and norms.

Last Updated: May 1, 2025

Vectors

ItemDescription
Vector: v = [v1, v2, ..., vn]Ordered list of numbers — point in n-dimensional space
Dot Product: v*w = Sum(v_i * w_i)Scalar — measures alignment: positive=same direction, 0=orthogonal
Norm (L2): ||v||_2 = sqrt(Sum(v_i^2))Euclidean length of vector — most common distance
Norm (L1): ||v||_1 = Sum(|v_i|)Manhattan distance — sum of absolute values, sparse-promoting
Cosine Similarity = (v*w) / (||v||*||w||)Similarity measure: 1.0 = same direction, 0 = orthogonal, -1 = opposite
Unit Vector = v / ||v||Vector with length 1 — preserves direction, normalizes scale

Matrices

ItemDescription
Matrix: A with m rows, n columnsm x n grid of numbers — linear transformation
Matrix AdditionElement-wise — requires same dimensions
Matrix Multiplication: C = A*BRows of A dot columns of B — A(mxk) * B(kxn) = C(mxn)
Transpose: A^TRows become columns: (A^T)_ij = A_ji
Inverse: A^(-1)Matrix such that A*A^(-1) = I — only for square, full-rank matrices
Determinant: det(A)Scalar — zero means singular (non-invertible); measures area/volume scaling

Eigenvalues & SVD

ItemDescription
Eigenvalue Equation: Av = lambda*vA transforms v by only scaling it (no rotation)
Eigendecomposition: A = V*Lambda*V^(-1)For diagonalizable matrices — A expressed in eigenbasis
Singular Value Decomposition: A = U*Sigma*V^TWorks for ANY matrix — U/V=orthogonal, Sigma=diagonal singular values
SVD InterpretationU: left singular vectors (output basis), Sigma: importance weights, V^T: right singular vectors (input basis)
Truncated SVD / Low-Rank ApproxKeep top-k singular values — best rank-k approximation (Eckart-Young)
PCA = SVD on centered dataPrincipal components = right singular vectors of centered data matrix

Common Operations in ML

ItemDescription
C = A @ B (Python: @ or dot)Matrix multiplication — core of neural network forward passes
Orthogonal Matrix: A^T*A = IColumns are orthonormal — preserves lengths (SVD, QR)
Trace: tr(A) = Sum(A_ii)Sum of diagonal elements — invariant under cyclic permutations
RankNumber of linearly independent rows/columns — dimensionality of column space
Pro Tip: SVD is the swiss army knife of linear algebra — it underlies PCA, pseudoinverses, low-rank approximations, and recommendation systems.