Skip to content

Norms

Before you can ask how far apart two vectors are, or which of them is bigger, or whether one is small enough to ignore, you need a way to turn a vector into a single number representing its size. That map is a norm, written x\lVert \mathbf{x} \rVert.

There is more than one. That is not a technicality to be filed away — the choice of norm is the difference between a regulariser that produces exactly-zero coefficients and one that never does, and this page ends by measuring that difference on a real fit.

  • The three properties a norm must have, and how to check a candidate against each.
  • The Manhattan (1\ell_1), Euclidean (2\ell_2) and maximum (\ell_\infty) norms, and the p\ell_p family that contains all three.
  • Why the unit ball — the set of vectors of length one — is the object to look at rather than the formula.
  • Why p<1p < 1 gives something that is not a norm, demonstrated with a two-line counterexample.
  • The measured reason Lasso produces exact zeros and Ridge does not, and the measured reason ridge coefficients are not even monotone in the penalty.

Intuition: three ways to price a taxi ride

Section titled “Intuition: three ways to price a taxi ride”

You are at the origin of a city laid out on a grid and you want to get to the corner (1.6,0.9)(1.6, 0.9) kilometres away. How far is that?

  • The taxi driver cares about kilometres of tarmac. There are no diagonal streets, so the trip is 1.6+0.9=2.51.6 + 0.9 = 2.5 km. That is the 1\ell_1 norm, and it is called the Manhattan norm for exactly this reason.
  • The pigeon flies straight over the buildings: 1.62+0.921.836\sqrt{1.6^2 + 0.9^2} \approx 1.836 km. That is 2\ell_2, the Euclidean norm.
  • The bureaucrat filling in a form with separate “blocks east” and “blocks north” fields, and a rule that says the trip is classified by whichever is larger, records 1.61.6. That is \ell_\infty, the maximum norm.

All three are correct. They answer different questions, and none of them is the length of the trip in some absolute sense. What the mathematics does is pin down the minimum a candidate has to satisfy before it deserves the word “length” at all.

diagram Diagram mermaid

The last arrow is the one worth carrying forward. Homogeneity means the norm is determined by its behaviour on the unit ball and nothing else: once you know which vectors have length one, scaling gives you every other length for free. So the picture of the ball is not an illustration of the norm — it is the norm.

Note what is not required. There is no requirement that a norm come from an inner product, no requirement that it be smooth, and no requirement that it treat the coordinate directions equally. Two of the three standard norms take advantage of that latitude.

Manhattan norm (1\ell_1), Example 3.1 in the book:

x1=i=1nxi\lVert \mathbf{x} \rVert_1 = \sum_{i=1}^{n} \lvert x_i \rvert

Euclidean norm (2\ell_2), Example 3.2:

x2=i=1nxi2=xx\lVert \mathbf{x} \rVert_2 = \sqrt{\sum_{i=1}^{n} x_i^2} = \sqrt{\mathbf{x}^\top \mathbf{x}}

Maximum norm (\ell_\infty):

x=maxixi\lVert \mathbf{x} \rVert_\infty = \max_i \lvert x_i \rvert

All three are members of one family, the pp-norm:

xp=(i=1nxip)1/p,p1\lVert \mathbf{x} \rVert_p = \left( \sum_{i=1}^{n} \lvert x_i \rvert^p \right)^{1/p}, \qquad p \geq 1

with p=1p = 1 and p=2p = 2 read off directly, and \ell_\infty arising as the limit pp \to \infty (the largest coordinate eventually dominates the sum, and taking the pp-th root strips off the rest).

The restriction is not decoration. Take the two standard basis vectors of R2\mathbb{R}^2 and test the triangle inequality on them. Each has eip=1\lVert \mathbf{e}_i \rVert_p = 1 for every pp, and their sum is (1,1)(1,1), so

e1+e2p=(1p+1p)1/p=21/p,e1p+e2p=2.\lVert \mathbf{e}_1 + \mathbf{e}_2 \rVert_p = (1^p + 1^p)^{1/p} = 2^{1/p}, \qquad \lVert \mathbf{e}_1 \rVert_p + \lVert \mathbf{e}_2 \rVert_p = 2 .

The inequality demands 21/p22^{1/p} \leq 2, which holds exactly when p1p \geq 1. Below that it fails, and by a wide margin:

ppe1+e2p=21/p\lVert \mathbf{e}_1 + \mathbf{e}_2 \rVert_p = 2^{1/p}e1p+e2p\lVert \mathbf{e}_1 \rVert_p + \lVert \mathbf{e}_2 \rVert_pverdict
0.54.0000002fails
0.63.1748022fails
0.82.3784142fails
1.02.0000002holds, with equality
2.01.4142142holds
\infty1.0000002holds

Geometrically, p<1p < 1 makes the unit ball cave inwards, and a non-convex ball is precisely what the triangle inequality forbids. Objects of this kind are called quasinorms; the ”0\ell_0 norm” counting nonzero entries is one of them, which is why sparse-recovery papers write it in quotation marks.

For any x\mathbf{x} and any 1pq1 \leq p \leq q,

x    xq    xp    x1.\lVert \mathbf{x} \rVert_\infty \;\leq\; \lVert \mathbf{x} \rVert_q \;\leq\; \lVert \mathbf{x} \rVert_p \;\leq\; \lVert \mathbf{x} \rVert_1 .

Larger pp never gives a larger answer. The reason is visible in the balls: as pp grows the ball inflates, and a bigger ball means a given vector needs less scaling to reach the boundary, which means a smaller measured length.

Take x=(1.6, 0.9)\mathbf{x} = (1.6,\ 0.9)^\top and measure it six ways.

ppworkingxp\lVert \mathbf{x} \rVert_p
11.6+0.91.6 + 0.92.500000
1.5(1.61.5+0.91.5)1/1.5=(2.02386+0.85381)0.6667(1.6^{1.5} + 0.9^{1.5})^{1/1.5} = (2.02386 + 0.85381)^{0.6667}2.023148
22.56+0.81=3.37\sqrt{2.56 + 0.81} = \sqrt{3.37}1.835756
3(4.096+0.729)1/3=4.8251/3(4.096 + 0.729)^{1/3} = 4.825^{1/3}1.689789
6(16.777216+0.531441)1/6=17.3086571/6(16.777216 + 0.531441)^{1/6} = 17.308657^{1/6}1.608338
\inftymax(1.6, 0.9)\max(1.6,\ 0.9)1.600000

Two things to notice. The sequence is decreasing in pp, as the ordering above requires. And it converges to 1.61.6 — the largest coordinate — from above: by p=6p = 6 the answer is already within 0.53%0.53\% of \ell_\infty, so the maximum norm is a good approximation to a fairly modest pp.

Verified against NumPy, which implements 1\ell_1, 2\ell_2 and \ell_\infty directly:

check_by_hand.py
import numpy as np
 
x = np.array([1.6, 0.9])
 
def pnorm(v, p):
    if np.isinf(p):
        return np.max(np.abs(v))
    return np.sum(np.abs(v) ** p) ** (1.0 / p)
 
for p in (1, 1.5, 2, 3, 6, np.inf):
    print(f"p = {str(p):>4}   ||x||_p = {pnorm(x, p):.6f}")
 
print("numpy agrees:", [round(float(np.linalg.norm(x, o)), 6) for o in (1, 2, np.inf)])
output
p =    1   ||x||_p = 2.500000
p =  1.5   ||x||_p = 2.023148
p =    2   ||x||_p = 1.835756
p =    3   ||x||_p = 1.689789
p =    6   ||x||_p = 1.608338
p =  inf   ||x||_p = 1.600000
numpy agrees: [2.5, 1.835756, 1.6]

The first sketch draws all three standard balls scaled so that each passes through the point you drag. The radius of each ball is the corresponding norm, so the three numbers in the readout are three distances you can see.

sketch Three rulers, one point p5.js
Drag the white point. Each ball is scaled so its boundary passes through it, so the radius of each ball is that norm's answer. The maximum norm always gives the smallest number and the Manhattan norm the largest — the balls are nested for that reason.

The second sketch puts the triangle inequality under a pp knob. Drag the two blue arrows, then drag pp below 1 and watch the ball cave in and the inequality break.

sketch The triangle inequality, and where it breaks p5.js
Two draggable vectors u and v, their sum, and the ball of radius equal to the sum of their two lengths. While p is at least 1 the sum stays inside that ball. Push p below 1 and the ball becomes non-convex and the sum escapes it — which is the triangle inequality failing.

And the stepped sweep, which keeps every previous ball as a trail so the deformation from diamond to circle to square reads as one continuous motion:

vectorOne vector, seven rulersunit balls of the p-norm
-2-1012-1-0.500.51x1x2xx / ‖x‖ = 3.91‖x‖_0.6 = 1not a norm: the boundary is not convex
p 0.6‖x‖_p 3.905‖e1+e2‖_p 3.175‖e1‖+‖e2‖ 2triangle fails
p0.6‖x‖_p3.905‖e1+e2‖ vs ‖e1‖+‖e2‖3.175 vs 2triangle inequalityFAILS
not a normp = 0.6. The probe (1.6, 0.9) measures 3.905 long, so dividing by that lands it on the ball — the white dot on the boundary. The ball has caved inwards, and that is fatal. A norm must satisfy the triangle inequality, and this shape does not — the watch panel below shows a pair of vectors whose sum is measured as longer than the two of them added. Values of p below one give a quasinorm, not a norm.
1/7

The white dot on the boundary is the probe divided by its own length, so it must land on the ball at every step. Watch the corners round off between p = 1 and p = 2, and note the first frame is not a norm at all.

One function covers the whole family, including the limit case:

norms_from_scratch.py
import numpy as np
 
def pnorm(v, p):
    """The p-norm of a vector. p may be np.inf."""
    if np.isinf(p):
        return np.max(np.abs(v))
    return np.sum(np.abs(v) ** p) ** (1.0 / p)
 
# The three defining properties, tested rather than assumed.
rng = np.random.default_rng(0)
x = rng.normal(size=5)
y = rng.normal(size=5)
lam = -2.7
 
for p in (1, 2, np.inf):
    homog = abs(pnorm(lam * x, p) - abs(lam) * pnorm(x, p))
    triangle = pnorm(x + y, p) <= pnorm(x, p) + pnorm(y, p) + 1e-12
    definite = pnorm(np.zeros(5), p) == 0.0 and pnorm(x, p) > 0
    print(f"p={str(p):>3}  homogeneity gap {homog:.2e}   triangle {triangle}   definite {definite}")
 
# And the counterexample for p below 1.
e1, e2 = np.array([1.0, 0.0]), np.array([0.0, 1.0])
for p in (0.5, 0.6, 0.8, 1.0):
    lhs, rhs = pnorm(e1 + e2, p), pnorm(e1, p) + pnorm(e2, p)
    print(f"p={p}  ||e1+e2||={lhs:.6f}  ||e1||+||e2||={rhs:.1f}  "
          f"{'holds' if lhs <= rhs + 1e-12 else 'FAILS'}")
output
p=  1  homogeneity gap 0.00e+00   triangle True   definite True
p=  2  homogeneity gap 4.44e-16   triangle True   definite True
p=inf  homogeneity gap 0.00e+00   triangle True   definite True
p=0.5  ||e1+e2||=4.000000  ||e1||+||e2||=2.0  FAILS
p=0.6  ||e1+e2||=3.174802  ||e1||+||e2||=2.0  FAILS
p=0.8  ||e1+e2||=2.378414  ||e1||+||e2||=2.0  FAILS
p=1.0  ||e1+e2||=2.000000  ||e1||+||e2||=2.0  holds

The homogeneity gap for 2\ell_2 is 4.44×10164.44 \times 10^{-16} rather than zero, because that norm goes through a square root and a multiplication. It is one unit in the last place, which is the correct amount of disagreement, not an error.

figure Three rulers on one arrow matplotlib
A diamond, a circle and a square drawn on one pair of axes, all passing through the points where a coordinate equals plus or minus one, with a single arrow to the point (1.6, 0.9) and a table giving its three measured lengths. A diamond, a circle and a square drawn on one pair of axes, all passing through the points where a coordinate equals plus or minus one, with a single arrow to the point (1.6, 0.9) and a table giving its three measured lengths.
The balls are nested — diamond inside circle inside square — which is exactly the inequality that makes the maximum norm the smallest answer and the Manhattan norm the largest. The four marked points on the axes are the only sharp corners of the diamond.
figure Equal budgets, unequal outcomes matplotlib
Elliptical loss contours of a two-coefficient regression with a diamond and a circle of equal area drawn over them, the unpenalised optimum marked with a star, and each constrained optimum marked and labelled with its second coefficient. Elliptical loss contours of a two-coefficient regression with a diamond and a circle of equal area drawn over them, the unpenalised optimum marked with a star, and each constrained optimum marked and labelled with its second coefficient.
The two constraint regions have the same area, so neither is being handicapped. The diamond's optimum sits on a corner where the second coefficient is exactly zero; the circle's sits on a smooth arc where it is 0.6056. The l1 fit pays 10.8% more squared error and uses one feature instead of two.
figure Exact elimination against indefinite shrinkage matplotlib
Two panels of coefficient trajectories against penalty strength on a log axis. In the lasso panel one coefficient reaches exactly zero and stays there, then the other follows. In the ridge panel both coefficients approach zero without reaching it, and one of them first rises before falling. Two panels of coefficient trajectories against penalty strength on a log axis. In the lasso panel one coefficient reaches exactly zero and stays there, then the other follows. In the ridge panel both coefficients approach zero without reaching it, and one of them first rises before falling.
Measured over 60 penalty values. Lasso sets w2 to exactly zero from lambda 22.70 onwards and w1 from lambda 126.38. Ridge never reaches zero — its smallest w1 over the whole path is 0.3297. Note also that ridge's w2 rises before it falls.

From the balls. The diamond has four corners and they all sit on the axes; the circle has none. That is the entire mechanism behind sparsity. An optimisation pushing outwards against a constraint boundary will generically stop at a point of the boundary, and a corner is a much larger target for a tilted contour than any single smooth point. A corner of the 1\ell_1 ball is a place where one coordinate is exactly zero.

From the equal-area comparison. Both regions cover 3.4643.464 square units, so the 1\ell_1 result is not an artefact of a tighter budget. The measured outcome: 1\ell_1 lands at (1.31598, 0)(1.31598,\ 0) with squared error 33.46233.462; 2\ell_2 lands at (0.85773, 0.60564)(0.85773,\ 0.60564) with squared error 30.21130.211. That is the actual trade — about 11%11\% more error for a model that reads one feature instead of two. Whether that trade is worth making is a modelling question, and the figure is what lets you price it.

From the paths. Two measured facts, one expected and one not.

The expected one: Lasso’s w2w_2 becomes exactly 0.00.0 at λ22.70\lambda \approx 22.70 and remains exactly zero for every larger penalty. Ridge’s smallest w1\lvert w_1 \rvert anywhere on the path is 0.32970.3297, and its w2w_2 bottoms out at 0.17500.1750. “Shrinks towards zero” and “sets to zero” are different behaviours and the plot shows the difference rather than describing it.

The unexpected one: ridge’s w2w_2 does not decrease monotonically. It starts at 0.17500.1750, climbs to a maximum of 0.62620.6262, and only then falls. The two features here correlate at 0.8790.879, and a circular constraint prefers to split a fixed budget across two correlated directions rather than spend it all on one — so tightening the penalty initially increases the smaller coefficient. The peak occurs at λ=22.695\lambda = 22.695, which is precisely the penalty at which Lasso deletes the same coefficient. Same data, same λ\lambda, opposite conclusion about w2w_2: one method calls it 0.62620.6262 and the other calls it 00.

If you have ever read a single ridge coefficient as a measure of a feature’s importance, that is the figure to remember.

normformulaunit ballsmooth?typical use
1\ell_1ixi\sum_i \lvert x_i \rvertdiamond, corners on the axesno (kinks at the axes)Lasso, sparse recovery, robust loss
2\ell_2ixi2\sqrt{\sum_i x_i^2}circleyesRidge, least squares, weight decay, distances
\ell_\inftymaxixi\max_i \lvert x_i \rvertsquareno (kinks at the edge midpoints)adversarial perturbation budgets, worst-case bounds
general p\ell_p, p>1p>1(ixip)1/p(\sum_i \lvert x_i \rvert^p)^{1/p}convex, interpolatingyes for p>1p>1rarely used directly; useful for theory
"0\ell_0"#{i:xi0}\#\{i : x_i \neq 0\}not a ballnothe thing 1\ell_1 is a convex surrogate for
MahalanobisxΣ1x\sqrt{\mathbf{x}^\top \Sigma^{-1}\mathbf{x}}ellipseyesdistances that respect correlation (§3.3)

The last row is the bridge to the next page: it is a norm, and it comes from an inner product other than the dot product.

pch.quizTag Check your understanding
  1. Why does the l1 ball produce exactly-zero coefficients when used as a constraint, while the l2 ball does not?

    pch.quizShowAnswer

    B — Because the l1 ball's only sharp corners lie on the axes, and a corner is where a coordinate is exactly zero — a tilted contour hits a corner generically, a smooth arc point only by coincidence — The figure on this page controls for size by giving both regions the same area, and the corner still wins. Nothing is rounded: the l1 optimum has w2 exactly 0.0 because the corner is at w2 = 0 exactly.

  2. For a fixed nonzero vector, which ordering of its norms always holds?

    pch.quizShowAnswer

    B — l-infinity <= l2 <= l1 — Larger p never gives a larger answer. Geometrically the balls are nested — diamond inside circle inside square — so a vector needs less scaling to reach the outer ball, hence a smaller measured length. Equality happens only for vectors along a coordinate axis.

  3. The p-norm formula is restricted to p at least 1. Which property fails below that, and what is the two-vector counterexample?

    pch.quizShowAnswer

    C — The triangle inequality fails; taking e1 and e2 gives 2 to the power 1/p on the left and 2 on the right, so it breaks as soon as p is below 1 — At p = 0.6 the left side is 3.174802 against a right side of 2. Geometrically the unit ball caves inwards, and a non-convex ball is exactly what the triangle inequality forbids.

  4. The measured ridge path on this page shows w2 rising from 0.1750 to 0.6262 before falling. What does that tell you?

    pch.quizShowAnswer

    B — Ridge does not shrink each coefficient monotonically when features are correlated — a circular constraint prefers to split a budget across correlated directions, so a single ridge coefficient is not a measure of feature importance — The ridge path is a closed-form solve, so there is nothing to converge; the features are standardised in the code that produced the figure. The two features correlate at 0.879, and at lambda = 22.695 — precisely where lasso deletes w2 — ridge reports its largest value for the same coefficient.

Exercise 2 – Break the triangle inequality

Section titled “Exercise 2 – Break the triangle inequality”

Exercise 5 – Reproduce the sparsity result

Section titled “Exercise 5 – Reproduce the sparsity result”
  • A norm needs three properties: absolutely homogeneous, satisfies the triangle inequality, and positive definite.
  • The unit ball determines the norm completely, because homogeneity fixes every other length once you know which vectors have length one.
  • Manhattan sums absolute values, Euclidean takes the square root of the sum of squares, maximum takes the largest absolute coordinate — and larger p never gives a larger answer.
  • The p-norm needs p at least 1: at p below one the two basis vectors give 2 to the power 1 over p on the left against 2 on the right, and the ball is not convex.
  • The l1 ball’s only corners lie on the axes, which is why an optimum pushed against it has coefficients that are exactly zero rather than merely small.
  • Ridge coefficients are not monotone in the penalty when features are correlated — the measured path on this page has one coefficient rise from 0.175 to 0.626 before falling.
  • The book’s default norm from here on is the Euclidean one, assumed silently in the least-squares, PCA and SVM chapters.

Next: Inner Products — where the Euclidean norm comes from, and what else can sit in its place.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading