AI Wiki中文/EN

Vector and matrix norms

向量与矩阵范数

Define the size of an error, compare L1, L2, and maximum norms, and distinguish matrix size from worst-case amplification.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

One large error or two smaller errors?

Suppose two prediction methods have residuals a=(5,0)a=(5,0) and b=(3,3)b=(3,3), with both coordinates in the same units. Which error is smaller? Summing absolute errors favors aa, with 5 rather than 6. Looking at the largest individual error favors bb, 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 ∥ax∥=∣a∣∥x∥\|ax\|=|a|\|x\| and the triangle inequality ∥x+y∥≤∥x∥+∥y∥\|x+y\|\leq\|x\|+\|y\|. Familiar choices are:

∥x∥1=∑i∣xi∣,∥x∥2=∑ixi2,∥x∥∞=max⁡i∣xi∣.\|x\|_1=\sum_i|x_i|,\qquad \|x\|_2=\sqrt{\sum_i x_i^2},\qquad \|x\|_\infty=\max_i|x_i|.

For x=(3,−4)x=(3,-4), the results are 7, 5, and 4. The L1 triangle inequality follows by summing ∣xi+yi∣≤∣xi∣+∣yi∣|x_i+y_i|\leq|x_i|+|y_i| over coordinates. The L2 proof uses the Cauchy–Schwarz inequality from the inner-products article. More generally, the pp norm is (∑i∣xi∣p)1/p(\sum_i|x_i|^p)^{1/p} for p≥1p\geq1. 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:

∥A∥F=∑i,jAij2,∥A∥2=max⁡∥x∥2=1∥Ax∥2.\|A\|_F=\sqrt{\sum_{i,j}A_{ij}^2},\qquad \|A\|_2=\max_{\|x\|_2=1}\|Ax\|_2.

The identity I2I_2 has Frobenius norm 2\sqrt2 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 O(d)O(d) time. Returning three numbers uses constant-sized output space; normalization additionally allocates an O(d)O(d) 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 dd-dimensional vector, ∥x∥∞≤∥x∥2≤∥x∥1\|x\|_\infty\leq\|x\|_2\leq\|x\|_1. 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

  1. What are the three norms of x=(1,1,1,1)x=(1,1,1,1)? Answer: L1 is 4, L2 is 2, and the maximum norm is 1.
  2. Use x=(1,0)x=(1,0) 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.
  3. Which aggregate here directly checks the worst individual error? Answer: the maximum norm, although actual business costs may need a separate model.
  4. The largest absolute entry of [1100]\begin{bmatrix}1&1\\0&0\end{bmatrix} is 1. Is its induced infinity norm also 1? Answer: no. Input (1,1)(1,1) has maximum norm 1 and output (2,0)(2,0) 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?

Choose one answer

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

  1. Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
    Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
  2. 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

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.