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 .
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.
What you’ll learn
Section titled “What you’ll learn”- The three properties a norm must have, and how to check a candidate against each.
- The Manhattan (), Euclidean () and maximum () norms, and the 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 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 kilometres away. How far is that?
- The taxi driver cares about kilometres of tarmac. There are no diagonal streets, so the trip is km. That is the norm, and it is called the Manhattan norm for exactly this reason.
- The pigeon flies straight over the buildings: km. That is , 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 . That is , 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.
flowchart TD N["a norm ‖·‖ : V → ℝ"] N --> H["absolutely homogeneous
‖λx‖ = |λ| ‖x‖
doubling a vector doubles its length"] N --> T["triangle inequality
‖x + y‖ ≤ ‖x‖ + ‖y‖
a detour is never shorter"] N --> P["positive definite
‖x‖ ≥ 0, and 0 only for x = 0
only the zero vector has no size"] H --> B["the unit ball
{x : ‖x‖ = 1}
determines the norm completely"] T --> C["the ball must be CONVEX
— this is the property p < 1 breaks"] P --> B
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.
The math
Section titled “The math”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.
The three standard norms
Section titled “The three standard norms”Manhattan norm (), Example 3.1 in the book:
Euclidean norm (), Example 3.2:
Maximum norm ():
All three are members of one family, the -norm:
with and read off directly, and arising as the limit (the largest coordinate eventually dominates the sum, and taking the -th root strips off the rest).
Why p must be at least 1
Section titled “Why p must be at least 1”The restriction is not decoration. Take the two standard basis vectors of and test the triangle inequality on them. Each has for every , and their sum is , so
The inequality demands , which holds exactly when . Below that it fails, and by a wide margin:
| verdict | |||
|---|---|---|---|
| 0.5 | 4.000000 | 2 | fails |
| 0.6 | 3.174802 | 2 | fails |
| 0.8 | 2.378414 | 2 | fails |
| 1.0 | 2.000000 | 2 | holds, with equality |
| 2.0 | 1.414214 | 2 | holds |
| 1.000000 | 2 | holds |
Geometrically, 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 ” norm” counting nonzero entries is one of them, which is why sparse-recovery papers write it in quotation marks.
The ordering that always holds
Section titled “The ordering that always holds”For any and any ,
Larger never gives a larger answer. The reason is visible in the balls: as 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.
Worked example by hand
Section titled “Worked example by hand”Take and measure it six ways.
| working | ||
|---|---|---|
| 1 | 2.500000 | |
| 1.5 | 2.023148 | |
| 2 | 1.835756 | |
| 3 | 1.689789 | |
| 6 | 1.608338 | |
| 1.600000 |
Two things to notice. The sequence is decreasing in , as the ordering above requires. And it converges to — the largest coordinate — from above: by the answer is already within of , so the maximum norm is a good approximation to a fairly modest .
Verified against NumPy, which implements , and directly:
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)])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]See it move
Section titled “See it move”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.
The second sketch puts the triangle inequality under a knob. Drag the two blue arrows, then drag below 1 and watch the ball cave in and the inequality break.
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:
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.
From scratch
Section titled “From scratch”One function covers the whole family, including the limit case:
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'}")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 holdsThe homogeneity gap for is 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.
On real data
Section titled “On real data”Reading the plot
Section titled “Reading the plot”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 ball is a place where one coordinate is exactly zero.
From the equal-area comparison. Both regions cover square units, so the result is not an artefact of a tighter budget. The measured outcome: lands at with squared error ; lands at with squared error . That is the actual trade — about 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 becomes exactly at and remains exactly zero for every larger penalty. Ridge’s smallest anywhere on the path is , and its bottoms out at . “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 does not decrease monotonically. It starts at , climbs to a maximum of , and only then falls. The two features here correlate at , 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 , which is precisely the penalty at which Lasso deletes the same coefficient. Same data, same , opposite conclusion about : one method calls it and the other calls it .
If you have ever read a single ridge coefficient as a measure of a feature’s importance, that is the figure to remember.
Pitfalls
Section titled “Pitfalls”Compare
Section titled “Compare”| norm | formula | unit ball | smooth? | typical use |
|---|---|---|---|---|
| diamond, corners on the axes | no (kinks at the axes) | Lasso, sparse recovery, robust loss | ||
| circle | yes | Ridge, least squares, weight decay, distances | ||
| square | no (kinks at the edge midpoints) | adversarial perturbation budgets, worst-case bounds | ||
| general , | convex, interpolating | yes for | rarely used directly; useful for theory | |
| "" | not a ball | no | the thing is a convex surrogate for | |
| Mahalanobis | ellipse | yes | distances 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.
-
Why does the l1 ball produce exactly-zero coefficients when used as a constraint, while the l2 ball does not?
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.
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.
-
For a fixed nonzero vector, which ordering of its norms always holds?
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.
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.
-
The p-norm formula is restricted to p at least 1. Which property fails below that, and what is the two-vector counterexample?
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.
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.
-
The measured ridge path on this page shows w2 rising from 0.1750 to 0.6262 before falling. What does that tell you?
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.
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.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Implement the p-norm
Section titled “Exercise 1 – Implement the p-norm”Exercise 2 – Break the triangle inequality
Section titled “Exercise 2 – Break the triangle inequality”Exercise 3 – The nesting of the balls
Section titled “Exercise 3 – The nesting of the balls”Exercise 4 – Draw a unit ball yourself
Section titled “Exercise 4 – Draw a unit ball yourself”Exercise 5 – Reproduce the sparsity result
Section titled “Exercise 5 – Reproduce the sparsity result”Recall card
Section titled “Recall card”- 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.coffeeCtapch.feedbackHeading
pch.feedbackSubheading