Unit 2 · Length, angle and the dot product

Lesson 15 · Available to read

L1 vs. L2 norms

Taxicab (L1) versus straight-line (L2) distance: two different ways to measure the size of a vector.

The Euclidean norm of lesson 7 is not the only reasonable way to measure size. Mathematicians call it the L2 norm and write it ‖v‖₂ = √(v₁² + … + vₙ²). A second common choice is the L1 norm, the sum of the absolute values of the components:

‖v‖₁ = |v₁| + |v₂| + … + |vₙ|.

For v = [3, −4], ‖v‖₂ = 5 while ‖v‖₁ = 3 + 4 = 7.

The L1 norm is also called the taxicab or Manhattan norm. In a city laid out on a grid, a taxi cannot drive diagonally through buildings; it must travel along streets, so the length of its route is the L1 distance, ‖a − b‖₁. The straight line, as the crow flies, is the L2 distance. Because a straight line is the shortest path, ‖v‖₂ ≤ ‖v‖₁ for every vector.

The two norms also give different shapes to the set of vectors of length 1. Under L2 it is the familiar unit circle; under L1 it is a diamond (a square rotated by 45°) with corners on the axes.

The choice matters in data analysis. L1 is less sensitive to a single very large component, and when used as a penalty in machine learning it tends to drive many parameters exactly to zero, producing simpler, sparse models.

A city-block path of length 7 versus a straight path of length 5 between the same points, and the circle and diamond of unit length

The takeaway

‖v‖₁ sums absolute components; ‖v‖₂ is straight-line length; always ‖v‖₂ ≤ ‖v‖₁.

Practice

0 of 5 attempted

  1. 1Calculate

    Compute the L1 and L2 norms of [3, −4].

    Saved in this browser

  2. 2Calculate

    Find both the L1 and L2 distances between [1, 1] and [4, 5].

    Saved in this browser

  3. 3Multiple choice

    Under the L1 norm, what shape is the set of all vectors of length 1 in the plane?

  4. 4Explain in your own words

    Explain geometrically why ‖v‖₂ ≤ ‖v‖₁.

    Saved in this browser

  5. 5Apply

    A courier in a grid city travels from block [2, 7] to block [6, 4]. How many blocks must they drive, and what is the straight-line distance?

    Saved in this browser