The L2 norm measures a vector’s length: square each component, add the squares, and take the square root. Geometrically, it is the diagonal length of a right triangle extended across every dimension. section 3.3 section 6.4.6
Use the L2 norm to:
- Calculate Euclidean distance by subtracting two vectors first, then measuring the L2 norm of their difference. section 3.3
- Normalize vectors by dividing each vector by its own L2 norm, giving vectors with length 1. section 6.4.6
- Relate vector length to cosine similarity, which divides a dot product by the L2 norm of each vector. section 3.3.1
Compute and normalize a vector
For vector [1, 2, 3, 4], the L2 norm is sqrt(1² + 2² + 3² + 4²), approximately 5.47. NumPy computes it with np.linalg.norm(vector), then normalizes the vector with vector / np.linalg.norm(vector). The same operation scales 300-dimensional sentence embeddings to a common length while preserving their directional differences. section 6.4.6 section 6.4.6
Figure 3.2 2D Euclidean distance
Inspect the two-dimensional geometry of Euclidean distance and the vector difference whose L2 norm supplies that distance. section 3.3


