Skip to content

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 x\lVert \mathbf{x} \rVert. 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): 32+42=5\sqrt{3^2 + 4^2} = 5 blocks.
  • As a taxi drives (Manhattan, following streets): 3+4=73 + 4 = 7 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 VV is a function :VR\lVert \cdot \rVert : V \to \mathbb{R} assigning each vector a length x\lVert \mathbf{x} \rVert, satisfying, for all λR\lambda \in \mathbb{R} and x,yV\mathbf{x}, \mathbf{y} \in V:

  • Absolutely homogeneous: λx=λx\lVert \lambda\mathbf{x} \rVert = |\lambda|\,\lVert \mathbf{x} \rVert
  • Triangle inequality: x+yx+y\lVert \mathbf{x} + \mathbf{y} \rVert \le \lVert \mathbf{x} \rVert + \lVert \mathbf{y} \rVert
  • Positive definite: x0\lVert \mathbf{x} \rVert \ge 0, and x=0    x=0\lVert \mathbf{x} \rVert = 0 \iff \mathbf{x} = \mathbf{0}

The triangle inequality is just “a detour is never shorter than going direct.”

The common norms

For xRn\mathbf{x} \in \mathbb{R}^n:

x1=i=1nxiManhattan (1),x2=i=1nxi2=xxEuclidean (2),x=maxiximax ().\underbrace{\lVert \mathbf{x} \rVert_1 = \sum_{i=1}^n |x_i|}_{\text{Manhattan } (\ell_1)}, \qquad \underbrace{\lVert \mathbf{x} \rVert_2 = \sqrt{\sum_{i=1}^n x_i^2} = \sqrt{\mathbf{x}^\top\mathbf{x}}}_{\text{Euclidean } (\ell_2)}, \qquad \underbrace{\lVert \mathbf{x} \rVert_\infty = \max_i |x_i|}_{\text{max } (\ell_\infty)}.

These are all special cases of the pp-norm xp=(ixip)1/p\lVert \mathbf{x} \rVert_p = \left(\sum_i |x_i|^p\right)^{1/p}.

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 pp slides from 1 upward:

sketch The unit ball of the p-norm p5.js
The set of all vectors with ‖x‖_p = 1, as p varies. p=1 is a diamond (Manhattan), p=2 is a circle (Euclidean), and large p approaches a square (max norm).

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

norms.py
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.0
norms.py
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.0
text
L1  (Manhattan): 7.0
L2  (Euclidean): 5.0
Linf (max)     : 4.0
default norm   : 5.0
text
L1  (Manhattan): 7.0
L2  (Euclidean): 5.0
Linf (max)     : 4.0
default norm   : 5.0

Why this matters for ML

  • L2 (Ridge) regularization adds w22\lVert \mathbf{w} \rVert_2^2 to the loss — it shrinks all weights smoothly toward zero. Its round unit ball has no corners.
  • L1 (Lasso) regularization adds w1\lVert \mathbf{w} \rVert_1 — 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 coffee

Was this page helpful?

Let us know how we did