Lensa ML
Lensa ML

How Norms & Distances Work

Step 1 of 6

The L2 (Euclidean) Norm

Straight-line distance from the origin

x3.00
y2.00
-4-224-4-224(3.0, 2.0)‖v‖₂ = 3.61
x
3.00
y
2.00
L2 NORM
3.606

This vector is far from the origin. The L2 norm grows as the straight-line distance from the origin increases.

Step 1 of 6: The L2 (Euclidean) Norm

Straight-line distance from the origin

x3.00
y2.00
-4-224-4-224(3.0, 2.0)‖v‖₂ = 3.61
x
3.00
y
2.00
L2 NORM
3.606

This vector is far from the origin. The L2 norm grows as the straight-line distance from the origin increases.

Step 2 of 6: The L1 (Manhattan) Norm

Distance measured along axes — the taxicab metric

x3.00
y2.00
-4-224-4-224(3.0, 2.0)|x|=3.0|y|=2.0L1 pathL2 line
L1 NORM
5.000
L2 NORM
3.606
L1 / L2 RATIO
1.387

The L1 norm (5.00) is significantly larger than L2 (3.61). The taxi must travel along grid lines while the crow flies straight. L1 ≥ L2 always holds.

Step 3 of 6: Unit Balls & Lp Norms

Watch the unit ball morph as p changes

p (norm order)2.00
-11-11xy‖x‖ p=2.0 = 1 unit ball
p VALUE
2.0
SHAPE
Circle
AREA
3.332

At p = 2, the unit ball is a perfect circle — the familiar Euclidean norm. All directions are treated equally, making it rotationally invariant.

Step 4 of 6: Distance Between Vectors

L1, L2, and L∞ — three ways to measure closeness

x₁-2.00
y₁1.00
x₂2.00
y₂3.00
-4-224-4-224A(-2.0,1.0)B(2.0,3.0)L1L2L∞
L1 DIST
6.000
L2 DIST
4.472
L∞ DIST
4.000

Three ways to measure the same gap: L1 (6.00) walks the grid, L2 (4.47) flies straight, and L∞ (4.00) only tracks the dominant axis. L∞ ≤ L2 ≤ L1 always holds.

Step 5 of 6: Cosine Similarity

Comparing direction, not magnitude

Angle₁ (degrees)30
Angle₂ (degrees)120
-11-11v₁v₂90°
ANGLE
90°
cos(θ)
0.000
DOT PRODUCT
0.000

The vectors are nearly perpendicular — cosine similarity ≈ 0. In embedding spaces, this means the items are unrelated or orthogonal concepts.

Step 6 of 6: Norms in ML

How L1 and L2 regularization constrain weights

w₁1.50
w₂2.00
λ (regularization strength)0.50
-3-113-3-113w₁w₂(w₁, w₂)L1 (Lasso)L2 (Ridge)
L1 PENALTY
1.750
L2 PENALTY
3.125
w₁
1.50
w₂
2.00

At λ = 0.50, the constraints tighten. Notice how the L1 diamond has corners on the axes — optimal solutions tend to land at those corners, zeroing out weights. L2's circle has no such preference.