Norms
Before we can talk about distance, angle, or “closeness,” we need to measure how big a vector is. That measurement is a norm, written . Surprisingly, there isn’t just one correct ruler — and the choice of ruler shows up directly in machine learning as the difference between Lasso and Ridge regularization.
A real-life example: getting across a city
You’re at one corner of a grid-like city and want to reach a point 3 blocks east and 4 blocks north. Two honest answers to “how far is it?“:
- As the crow flies (Euclidean): blocks.
- As a taxi drives (Manhattan, following streets): blocks.
Both are legitimate lengths. Which one is “right” depends on how you’re allowed to move — and that is exactly what choosing a norm decides.
Definition
A norm on a vector space is a function assigning each vector a length , satisfying, for all and :
- Absolutely homogeneous:
- Triangle inequality:
- Positive definite: , and
The triangle inequality is just “a detour is never shorter than going direct.”
The common norms
For :
These are all special cases of the -norm .
The shape of a ruler: the unit ball
The clearest way to see the difference between norms is to draw the unit ball — every vector of length exactly 1. For the Euclidean norm that’s a circle; for Manhattan it’s a diamond; for the max norm it’s a square. Watch the unit ball morph as slides from 1 upward:
Same vectors, different rulers — and the shape of “length 1” is completely different. That shape is exactly why L1 and L2 behave so differently in ML.
NumPy
import numpy as np
x = np.array([3.0, 4.0])
print("L1 (Manhattan):", np.linalg.norm(x, 1)) # 7.0
print("L2 (Euclidean):", np.linalg.norm(x, 2)) # 5.0
print("Linf (max) :", np.linalg.norm(x, np.inf))# 4.0
# L2 is the default
print("default norm :", np.linalg.norm(x)) # 5.0import numpy as np
x = np.array([3.0, 4.0])
print("L1 (Manhattan):", np.linalg.norm(x, 1)) # 7.0
print("L2 (Euclidean):", np.linalg.norm(x, 2)) # 5.0
print("Linf (max) :", np.linalg.norm(x, np.inf))# 4.0
# L2 is the default
print("default norm :", np.linalg.norm(x)) # 5.0L1 (Manhattan): 7.0
L2 (Euclidean): 5.0
Linf (max) : 4.0
default norm : 5.0L1 (Manhattan): 7.0
L2 (Euclidean): 5.0
Linf (max) : 4.0
default norm : 5.0Why this matters for ML
- L2 (Ridge) regularization adds to the loss — it shrinks all weights smoothly toward zero. Its round unit ball has no corners.
- L1 (Lasso) regularization adds — its diamond unit ball has corners on the axes, which is precisely why Lasso drives some weights to exactly zero (automatic feature selection).
- Distance metrics in k-NN and clustering are norms of difference vectors; switching the norm changes which points count as “near.”
🧪 Try It Yourself
Exercise 1 – Compute three norms
Exercise 2 – Verify the triangle inequality
Exercise 3 – Why Lasso zeros weights
Recap
- A norm measures a vector’s length; it must be homogeneous, obey the triangle inequality, and be positive definite.
- The common norms are L1 (Manhattan), L2 (Euclidean), and L∞ (max) — different rulers with differently-shaped unit balls (diamond, circle, square).
- The norm you pick has real consequences: L1 → sparse (Lasso), L2 → smooth shrinkage (Ridge).
Next: the object that most norms come from — the inner product.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
