Search

Search papers and lessons

Vector Norm

Level 2 · 8 min read

A vector norm is a single non-negative number that gives a vector's length, and the Euclidean norm is the length you would measure with a ruler.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

A vector is a list of numbers, so it has no obvious size. A norm is a rule that turns a vector into one non-negative number, its length. The most common norm, the Euclidean or ℓ2\ell_2 norm, is the straight-line length of the arrow the vector describes: square each entry, add them up, and take the square root.

Norms also give you distance. The distance between two vectors is the norm of their difference.

Where you'll see it: in the weight penalty of a regularised model, in clipping exploding gradients by their total size, and in normalising embeddings so that they all have length 1.

Intuition

Length for a list of numbers

Take the vector (3,4)(3, 4) and draw it as an arrow from the origin. The arrow goes 3 units right and 4 units up. Its length is the hypotenuse of a right triangle with those two legs, so Pythagoras gives 32+42=5\sqrt{3^2 + 4^2} = 5.

The same idea works in any number of dimensions. A vector with a hundred entries is an arrow in a hundred-dimensional space, and its length is still the square root of the sum of the squared entries. We cannot draw that space, but the arithmetic is identical.

Why we need a rule, not just a formula

A list of numbers can be measured in several sensible ways. Walking along a city grid, you pay the sum of the absolute values of the moves, not the straight-line distance. Machine learning uses both. So the right question is not "what is the length" but "which notion of size are we using", and a norm is the name for any notion that behaves like a length.

Three properties make a function a norm:

  1. Non-negative and zero only at zero. A length is never negative, and only the zero vector has length zero.
  2. Scaling. Doubling a vector doubles its length: ∥cv∥=∣c∣ ∥v∥\|c\mathbf{v}\| = |c|\,\|\mathbf{v}\|.
  3. Triangle inequality. Going from 0\mathbf{0} to u\mathbf{u} and then to u+v\mathbf{u}+\mathbf{v} is never shorter than going directly: ∥u+v∥≤∥u∥+∥v∥\|\mathbf{u}+\mathbf{v}\| \le \|\mathbf{u}\| + \|\mathbf{v}\|.

The Euclidean norm satisfies all three. So does the sum of absolute values. Any function with these three properties is a norm, and the rest of the theory only uses them.

−3−2−1012301234xnorm
  • length of (x, 1)
  • length of (x, 2)
  • length of (x, 0)
The Euclidean length of the vector (x, c) is the square root of x squared plus c squared. The dashed line is |x|, the length of (x, 0). Adding a second coordinate only lifts the curve; it never makes the length smaller.

The math

Definition

Definition: Euclidean norm

For a vector v=(v1,v2,…,vn)\mathbf{v} = (v_1, v_2, \dots, v_n) in Rn\mathbb{R}^n, the Euclidean norm (also called the ℓ2\ell_2 norm) is

∥v∥=v12+v22+⋯+vn2=∑i=1nvi2.\|\mathbf{v}\| = \sqrt{v_1^2 + v_2^2 + \cdots + v_n^2} = \sqrt{\sum_{i=1}^{n} v_i^2}.

Here viv_i is the entry of v\mathbf{v} in position ii. The sum adds the squared entries, and the square root undoes the squaring so the result is in the same units as the entries. The double bars ∥⋅∥\|\cdot\| mean "norm of", and a plain v\mathbf{v} in bold is a vector.

Triangle inequality, with numbers

Let u=(3,4)\mathbf{u} = (3, 4) and v=(1,0)\mathbf{v} = (1, 0).

  1. ∥u∥=5\|\mathbf{u}\| = 5 and ∥v∥=1\|\mathbf{v}\| = 1, so the right side of the inequality is 5+1=65 + 1 = 6.
  2. u+v=(4,4)\mathbf{u} + \mathbf{v} = (4, 4), and ∥(4,4)∥=32≈5.657\|(4,4)\| = \sqrt{32} \approx 5.657.
  3. 5.657≤65.657 \le 6, as the inequality promised.

The gap of about 0.34 is the cost of not walking in a perfectly straight line.

Other norms, for comparison

The same family of definitions gives other norms. The ℓ1\ell_1 norm adds absolute values, ∥v∥1=∑i∣vi∣\|\mathbf{v}\|_1 = \sum_i |v_i|. For (3,−4)(3, -4) it gives 3+4=73 + 4 = 7, compared with 55 for the Euclidean norm. Both are norms because they pass the three tests above.

Connection to the dot product

Dotting a vector with itself gives its squared length, as covered in the dot product:

v⋅v=∥v∥2.\mathbf{v} \cdot \mathbf{v} = \|\mathbf{v}\|^2.

This is why the Euclidean norm is so convenient. Lengths and angles are both built from the dot product, and the square root is only needed when you want the length itself rather than its square.

flowchart LR
  V[Vector v] --> S[Square each entry]
  S --> A[Add the squares]
  A --> R[Square root]
  R --> N[Length of v]
  N --> D[Distance between two vectors via their difference]

Worked examples

Example
A small vector by hand

Let v=(1,−2,2)\mathbf{v} = (1, -2, 2).

  1. Square each entry: 12=11^2 = 1, (−2)2=4(-2)^2 = 4, 22=42^2 = 4.
  2. Add the squares: 1+4+4=91 + 4 + 4 = 9.
  3. Take the square root: ∥v∥=9=3\|\mathbf{v}\| = \sqrt{9} = 3.

The sign of each entry disappears when it is squared, so (1,2,2)(1, 2, 2) and (−1,−2,−2)(-1, -2, -2) have the same length. Opposite vectors point in opposite directions but have the same size.

Example
Distance between two points

A point in a plane is a vector. The distance between a=(1,2)\mathbf{a} = (1, 2) and b=(4,6)\mathbf{b} = (4, 6) is the length of the difference a−b\mathbf{a} - \mathbf{b}.

  1. Subtract entry by entry: a−b=(1−4, 2−6)=(−3,−4)\mathbf{a} - \mathbf{b} = (1-4,\ 2-6) = (-3, -4).
  2. Take the norm: ∥(−3,−4)∥=9+16=25=5\|(-3, -4)\| = \sqrt{9 + 16} = \sqrt{25} = 5.

So the two points are 5 units apart. This is the usual Pythagorean distance, written as a norm.

Example
Normalising a vector to length 1

Take v=(3,4)\mathbf{v} = (3, 4), which has length 5 from before. Divide every entry by the length:

v∥v∥=(35, 45)=(0.6, 0.8).\frac{\mathbf{v}}{\|\mathbf{v}\|} = \left(\frac{3}{5},\ \frac{4}{5}\right) = (0.6,\ 0.8).

Check: 0.62+0.82=0.36+0.64=10.6^2 + 0.8^2 = 0.36 + 0.64 = 1, so the new vector has length 1. It points in the same direction as v\mathbf{v} and only its size has been removed. This is what "normalising" an embedding means in practice.

Tradeoffs and failure modes

SituationProblemBetter choice
Comparing directions only (for example, text embeddings)Length changes the score even when the direction is the sameNormalise first, or use cosine similarity
Sparse data where most entries are zeroEuclidean norm treats a small change in many entries the same as a big change in oneConsider the ℓ1\ell_1 norm, which encourages zeros
Very large or very small entriesSquaring can overflow or lose precision in floating pointScale the vector by its largest entry before squaring
Robustness to a single outlier entryOne huge entry dominates the sum of squaresUse ℓ1\ell_1 or a clipped norm

The usual failure in practice is mixing scales. If one feature is measured in metres and another in millimetres, the norm is dominated by the millimetre feature, and the distance no longer means what you intended. Standardise the features before you measure distance.

History

The idea of length comes from Pythagoras and the geometry of right triangles, long before anyone wrote it as a formula over lists of numbers. Writing a length as the square root of a sum of squared coordinates became standard once analytic geometry used coordinates. The abstract axioms of a norm were formalised by Stefan Banach and others in the 1920s and 1930s, when mathematicians started studying spaces of functions as well as spaces of arrows. The Euclidean norm is the case that matches everyday measurement, and it stayed the default because it is smooth, it fits with the dot product, and its square has a simple expansion.

Check yourself

QuestionWhat is the Euclidean norm of v=(2,3,6)\mathbf{v} = (2, 3, 6)?Show answer

Square the entries: 4+9+36=494 + 9 + 36 = 49. Take the square root: ∥v∥=49=7\|\mathbf{v}\| = \sqrt{49} = 7. The length is 7.

QuestionWhy is the norm of a vector never negative, and when is it zero?Show answer

Each squared entry is zero or positive, so their sum is non-negative, and so is its square root. The sum is zero only when every entry is zero, so the norm is zero only for the zero vector. Any other vector has a strictly positive length.

QuestionCompute the distance between (0,0)(0, 0) and (5,12)(5, 12).Show answer

The distance is the norm of the difference (5,12)−(0,0)=(5,12)(5, 12) - (0, 0) = (5, 12). Then 25+144=169=13\sqrt{25 + 144} = \sqrt{169} = 13. The distance is 13.

QuestionYou scale a vector v\mathbf{v} by c=−3c = -3. How does its norm change?Show answer

The scaling property says ∥cv∥=∣c∣ ∥v∥\|c\mathbf{v}\| = |c|\,\|\mathbf{v}\|. The sign of cc is removed by the absolute value, so the norm becomes 3 ∥v∥3\,\|\mathbf{v}\|. The vector points the opposite way but is three times as long.

QuestionA data scientist normalises every embedding to length 1 before comparing them. Why does this make comparisons about direction rather than size?Show answer

If every vector has length 1, then the only thing left to differ between two vectors is their direction. Length can no longer make one embedding look more similar to another, so dot products of normalised vectors become measures of the angle between them alone.

Sources