Home / Maths for AI / Symbols / Vectors and matrices

Norm (length)

Say it: "the norm of x"

What it means

The length of a vector. The usual (L2) norm is ∥x∥2=∑xi2\|\mathbf{x}\|_2 = \sqrt{\sum x_i^2}; the L1 norm is ∑∣xi∣\sum |x_i|.

Example

∥(3,4)∥2=5,∥(3,4)∥1=7\|(3, 4)\|_2 = 5, \quad \|(3, 4)\|_1 = 7

Straight-line distance vs grid (taxi) distance.

In code

import numpy as np
x = np.array([3, 4])
print(np.linalg.norm(x), np.linalg.norm(x, 1))

Output

5.0 7.0

Where it appears in machine learning

Distances between data points, L2 and L1 regularisation (λ∥w∥2\lambda \|\mathbf{w}\|^2), and normalising embeddings.

Related symbols

Learn it properly in the free lesson Vectors, Norms & the Dot Product, with practice questions that check your answers.