Vector and Matrix Norms
To say that a computed solution is "close" to the true one, or that an error is "small", we need to measure the size of vectors and matrices. Norms do this. This lesson defines the common vector norms, the matrix norms they induce, and the inequalities used in every error bound for linear systems.
Vector norms
A norm satisfies with equality only for , , and the triangle inequality . The three standard ones:
In all norms are equivalent: for example . They differ by at most a factor depending on , so "converges in one norm" means "converges in all".
import numpy as np
x = np.array([3.0, -4.0, 1.0, 0.0])
for p in (1, 2, np.inf):
print(f"||x||_{p} = {np.linalg.norm(x, p):.6f}")
print("inf <= 2 <= sqrt(n) inf:", np.linalg.norm(x, np.inf) <= np.linalg.norm(x) <= 2 * np.linalg.norm(x, np.inf))||x||_1 = 8.000000
||x||_2 = 5.099020
||x||_inf = 4.000000
inf <= 2 <= sqrt(n) inf: True
Induced matrix norms
The norm of a matrix induced by a vector norm is the largest stretching factor:
It follows immediately that and . For the three vector norms there are explicit formulas:
| Norm | Formula |
|---|---|
| maximum absolute column sum | |
| maximum absolute row sum | |
| largest singular value = |
The Frobenius norm is not induced by a vector norm but is easy to compute and satisfies .
import numpy as np
A = np.array([[1.0, -2.0], [3.0, 4.0]])
print("1-norm :", np.linalg.norm(A, 1), "= max column sum", np.max(np.sum(np.abs(A), axis=0)))
print("inf-norm:", np.linalg.norm(A, np.inf), "= max row sum", np.max(np.sum(np.abs(A), axis=1)))
print(f"2-norm : {np.linalg.norm(A, 2):.6f} = sigma_1 {np.linalg.svd(A, compute_uv=False)[0]:.6f}")
print(f"Frobenius: {np.linalg.norm(A, 'fro'):.6f}")
rng = np.random.default_rng(8)
X = rng.normal(size=(2, 100_000))
ratios = np.linalg.norm(A @ X, axis=0) / np.linalg.norm(X, axis=0)
print(f"largest stretch among 100000 random vectors: {ratios.max():.6f}")1-norm : 6.0 = max column sum 6.0
inf-norm: 7.0 = max row sum 7.0
2-norm : 5.116673 = sigma_1 5.116673
Frobenius: 5.477226
largest stretch among 100000 random vectors: 5.116673
Why norms matter here
The error bounds in the next lesson have the form
which only makes sense once vector and matrix sizes are measured consistently (Conditioning of Linear Systems).
In software
np.linalg.norm(x, ord)handles vectors and matrices;axis=computes norms of rows or columns at once.- Machine learning uses (lasso, sparsity) and (ridge, weight decay) as penalties, and spectral norms for Lipschitz constraints in GANs (Norms).
Exercises
Exercise 1: Vector norms
Compute the 1-, 2- and -norms of .
Answer
5, 3, 2.
Solution
; ; .
Exercise 2: Matrix norms by hand
Find and for .
Answer
, .
Solution
Column sums and ; row sums and .
Exercise 3: The worst vector (code)
The 2-norm is attained at the first right singular vector . Verify that for .
Answer
Both equal (rounded).
Solution
import numpy as np
A = np.array([[1.0, -2.0], [3.0, 4.0]])
U, s, Vt = np.linalg.svd(A)
v1 = Vt[0]
print(round(float(np.linalg.norm(A @ v1)), 6), round(float(s[0]), 6))5.116673 5.116673
Test yourself
The matrix -norm equals…
- the largest column sum of absolute values
- the largest row sum of absolute values
- the largest singular value
- the largest entry
The matrix 2-norm equals…
- the largest eigenvalue of
- the largest singular value of
- the Frobenius norm
- the determinant
Which inequality holds for any induced norm?