Singular value decomposition
Quick answer
Singular value decomposition (SVD) factors any real m-by-n matrix A into U Σ Vᵀ. In reduced SVD, r = min(m,n), U is m-by-r, Σ is r-by-r diagonal, and Vᵀ is r-by-n. U and V have orthonormal columns; singular values are nonnegative and conventionally sorted largest first. The factorization describes input directions, their stretching, and output directions. Unlike an eigendecomposition, it works directly with rectangular matrices.
Interpret singular values of a diagonal matrix
For diag(3, -2), the second coordinate reverses direction but its length scales by 2. Singular values measure stretching magnitudes, not signed eigenvalues. An elementary diagonal example avoids needing a general SVD algorithm.
diagonal = [3, -2]print(sorted([abs(x) for x in diagonal], reverse=True))print(sum(x*x for x in diagonal))Expected output:
[3, 2]13The singular values are 3 and 2, not 3 and −2. Their squared sum equals the squared Frobenius norm (sum of squared matrix entries).
Reconstruct a rectangular matrix
Optional local lab (Python 3.13.5, NumPy 2.3.5, CPU, float64). np.linalg.svd(A, full_matrices=False) returns U, the one-dimensional array s, and Vh (Vᵀ for real matrices). Broadcasting U * s scales each column. AᵀA has eigenvalues equal to squared singular values, with extra zeros as needed. We do not form AᵀA to compute SVD: doing so can magnify conditioning problems.
import numpy as npA = np.array([[3., 0.], [0., 2.], [0., 0.]])U, s, Vh = np.linalg.svd(A, full_matrices=False)print(U.shape, s.shape, Vh.shape)print(s.round(8).tolist())print(bool(np.allclose((U*s) @ Vh, A, atol=1e-12, rtol=1e-12)))print(bool(np.allclose(Vh @ Vh.T, np.eye(2), atol=1e-12, rtol=1e-12)))Expected output:
(3, 2) (2,) (2, 2)[3.0, 2.0]TrueTrueThe output reconstructs A and the right singular directions are orthonormal. Singular vectors may change signs together, and repeated singular values allow changes of basis. Compare reconstruction, orthogonality and singular values within tolerance.
Common mistakes
Do not multiply U by Vh without s; this loses the stretching factors. Do not assume s is already a diagonal matrix. A rectangular matrix has singular values but ordinary eigenvalues are defined for square matrices only. Tiny nonzero computed singular values do not necessarily prove exact full rank.
Practice and next steps
Predict reduced SVD shapes for a 2-by-5 matrix. Then explain why a negative eigenvalue does not imply a negative singular value. Next, keep only the strongest singular directions.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Singular value decomposition — knowledge check
Apply matrix geometry to small numerical fixtures.
Reduced SVD of a 2-by-5 matrix has U shape?
What are singular values of diag(-6,2)?
What does s contain in NumPy reduced SVD?
Which identity checks reconstruction?
Why avoid requiring exact singular-vector signs?