Vector and matrix norms
向量与矩阵范数
Define the size of an error, compare L1, L2, and maximum norms, and distinguish matrix size from worst-case amplification.
normsOne large error or two smaller errors?
Suppose two prediction methods have residuals and , with both coordinates in the same units. Which error is smaller? Summing absolute errors favors , with 5 rather than 6. Looking at the largest individual error favors , with 3 rather than 5. Neither calculation is wrong; the meaning of size differs.
A norm assigns a length to a vector. Taking a norm of the difference between two vectors defines a distance. Choosing a norm is a modeling decision: it specifies how coordinate differences are aggregated and affects a training procedure’s preferences over errors and parameters. This is a constructed example, not evidence that one metric is universally superior.
What rules should length obey?
A norm on a real vector space is nonnegative and zero only for the zero vector. It obeys and the triangle inequality . Familiar choices are:
For , the results are 7, 5, and 4. The L1 triangle inequality follows by summing over coordinates. The L2 proof uses the Cauchy–Schwarz inequality from the inner-products article. More generally, the norm is for . MML, Sections 3.1–3.4
The machine-learning expression “L0 norm” usually means the number of nonzero coordinates. It fails the scaling rule and is not strictly a norm. Squared L2 is not a norm either: doubling a vector quadruples its squared length. It remains a useful objective function, with different mathematical properties.
For matrices, distinguish two questions. The Frobenius norm measures all entries as one long vector. The induced 2-norm asks how much the matrix can amplify a unit vector:
The identity has Frobenius norm and induced 2-norm 1, because it preserves every vector’s length. The latter equals the largest singular value. Always identify which matrix norm an author means. Deep Learning, Section 2.5
Compare the errors directly
This complete Python example calculates three norms for nonempty vectors with finite real coordinates and normalizes nonzero vectors. hypot avoids some intermediate overflow risks associated with explicitly squaring before summation.
import math
def vector_norms(x):
if not x or any(not math.isfinite(v) for v in x):
raise ValueError("expected nonempty finite coordinates")
return math.fsum(abs(v) for v in x), math.hypot(*x), max(map(abs, x))
def normalize(x):
length = vector_norms(x)[1]
if length == 0:
raise ValueError("cannot normalize zero")
return [v / length for v in x]
assert vector_norms([3, -4]) == (7, 5, 4)
assert vector_norms([5, 0])[0] < vector_norms([3, 3])[0]
assert vector_norms([5, 0])[1] > vector_norms([3, 3])[1]
assert abs(math.hypot(*normalize([3, -4])) - 1) < 1e-12
assert vector_norms([0, 0]) == (0, 0, 0)
Vector norms take time. Returning three numbers uses constant-sized output space; normalization additionally allocates an vector. Computing a general dense matrix’s exact spectral norm cannot be replaced by the same entrywise loop: it typically involves a singular-value problem. Iterative methods can estimate worst-case amplification for large matrices.
Scale, dimension, and regularization
With incompatible coordinate units, a norm may mostly measure the chosen measurement scale. Even coordinates with matching units can differ in importance. State whether scaling or weighting is needed rather than assuming that coordinates are interchangeable.
For a -dimensional vector, . This does not make raw norms directly comparable across dimensions. Repeating the same per-coordinate error more times changes the aggregate. Mean, total, and maximum error answer different questions.
L1 and squared-L2 parameter penalties create different optimization geometries. L1 is often used to encourage sparsity, but its name alone does not guarantee a fixed number of zero parameters. Data, constraints, penalty strength, and the optimization method also determine the result.
Test a definition with counterexamples
- What are the three norms of ? Answer: L1 is 4, L2 is 2, and the maximum norm is 1.
- Use and coefficient 2 to show why a nonzero count is not a norm. Answer: the count stays 1, whereas absolute homogeneity requires it to become 2.
- Which aggregate here directly checks the worst individual error? Answer: the maximum norm, although actual business costs may need a separate model.
- The largest absolute entry of is 1. Is its induced infinity norm also 1? Answer: no. Input has maximum norm 1 and output has maximum norm 2. The largest absolute row sum is 2.
Error bounds describe geometry
Stability analyses use matrix norms to bound amplification of input perturbations. Gradient clipping uses a norm to detect an excessive update, orthogonal projection uses distance to find a best approximation, and regularization charges for parameter size. In each setting, write the chosen norm into the assumptions rather than treating it as incidental notation.
Make a prediction, then check
For residuals a=(5,0) and b=(3,3), which statement is correct?
Learning objectives
- Compare L1, L2, and maximum norms on the same residual example.
- Distinguish Frobenius and induced matrix norms.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Deep Learning — Chapter 2: Linear Algebra
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Recomputed norms 7/5/4 for (3,−4) and the differing error rankings for (5,0) and (3,3).
- Checked why L0 and squared L2 are not norms, and the Frobenius/induced 2-norms of I₂.
- Compared the main arguments, numerical examples, exercises, and answers across languages; structural checks additionally compare display equations, source lists, and code.
- Reviewed the answer-label rendering fix: only Markdown emphasis markers changed to strong tags; normalized text and all code are identical.
Source locations checked:
Related topics