Math for AI course · Lesson 39 of 180
Vector Norms Measure Size, Not Meaning
Calculate L1, L2, and L-infinity vector norms, verify their defining rules, and see what an embedding magnitude can—and cannot—tell you.
Two embedding vectors can point in the same direction and still have different magnitudes. For example, and are scaled copies: the second is twice as long. A norm turns a vector into a nonnegative number that summarizes its size according to a specified rule. That number can help compare scales or describe a parameter penalty, but it does not rank how meaningful an embedding is.
By the end of this lesson, you will be able to calculate the , , and vector norms, check the properties that make a function a norm, and use NumPy to compute vector sizes without confusing a batch of vectors for one matrix.
Learning outcome: Compute common vector norms and check the norm properties.
This lesson builds on Lesson 014: Vectors as AI Data, where coordinates were features in a fixed order. Section 3.1 of Mathematics for Machine Learning introduces norms as ways to measure vector length. The examples, code, visual, and assessments here are original.
A norm is a size rule with three promises
Let and be vectors in , and let be any real number. A function is a vector norm if it satisfies all three rules:
The first rule says a vector’s size cannot be negative, and only the zero vector has size zero. The second says scaling a vector by a negative number still multiplies its size by the scalar’s absolute value. The third says combining two vectors cannot produce a size larger than the sum of their separate sizes.
Three common rules applied to one vector
For , the common norms are
The subscript selects the rule. adds absolute coordinate sizes, uses the familiar Euclidean length, and keeps the largest absolute coordinate. These are three different summaries of the same vector; the coordinates themselves do not change.
Take the vector . Its negative second coordinate matters for some operations, but each of these size rules uses absolute values or squares:
The Euclidean unit ball is the set of two-coordinate vectors whose norm is at most one. The point lies on its boundary because .
L₂ unit ball: ‖x‖₂ ≤ 1
The shaded region encodes a rule, not just a shape: it contains the origin and every vector whose length is no greater than one. The boundary is where the length equals one. In higher dimensions the same set is called a ball too, even though it is no longer something we can draw as a disk.
Check the three promises
Positive definiteness follows directly for each formula. A sum of absolute values or squares can be zero only when every coordinate is zero. A maximum of absolute values is zero only when every coordinate is zero. Each formula is nonnegative, and each returns zero for the zero vector.
For absolute homogeneity, take and multiply it by :
The absolute value on is essential. A negative scalar flips the vector’s direction, but length does not become negative.
The triangle inequality can also be checked from the formulas. For , the coordinate rule holds for each coordinate, so summing those inequalities gives . For , it is the familiar geometric fact that one side of a triangle is no longer than the other two sides combined. For ,
Each norm therefore passes all three checks. A single numerical example can test whether you understand a rule, while the reasoning above explains why the rules hold for every vector.
Compute vector sizes with NumPy
NumPy exposes these calculations through
numpy.linalg.norm.
For a one-dimensional array, specify ord to choose a vector norm:
import numpy as np
x = np.array([3.0, -4.0])
print(np.linalg.norm(x, ord=1))
print(np.linalg.norm(x, ord=2))
print(np.linalg.norm(x, ord=np.inf))
The output is 7.0, 5.0, and 4.0. Omitting ord for a one-dimensional
array defaults to the norm.
An embedding table is often a two-dimensional array, with one embedding per row. To get one norm per embedding, specify the row axis:
embeddings = np.array([[3.0, 4.0], [6.0, 8.0]])
row_norms = np.linalg.norm(embeddings, ord=2, axis=1)
print(row_norms)
The output is [5. 10.]. The second vector has twice the first one’s norm,
even though both point in the same direction. With a two-dimensional input and
no axis, NumPy interprets the input as a matrix; a matrix norm is not the
same operation as calculating a vector norm for each row. The documentation
describes axis as the choice of dimension along which vector norms are
computed.
A vector norm says how large a representation is under a chosen coordinate rule. It does not say the larger embedding is more relevant, accurate, or semantically important. Those conclusions require a model-specific task and evaluation; the scalar magnitude alone cannot supply them.
A parameter penalty is related to a norm, but not always the norm itself
An optimization objective can add a term that penalizes large parameter vectors . For example, an penalty adds , while a squared penalty adds , with controlling the penalty’s weight. For , while .
The square in the second expression is important: is not itself a norm. Norm homogeneity scales it by , not by : . The two penalty formulas also have different numerical scales, so choosing the same does not make their effects comparable. The vector norm explains what a penalty measures; the objective and its coefficient determine how that measurement affects training.
One software detail deserves care. NumPy’s ord parameter supports values
below 1 for numerical purposes, but its documentation explicitly says those
results are not mathematical norms. For example, if
, then and , while
. Since , the triangle inequality fails. Use ord=0.5
when you specifically need that numerical expression, not when you need a
vector norm with the three guarantees above.
With the promises and the implementation distinction clear, the next step is to compare the geometries different valid norms create—and how those choices change notions of distance and constraint.
Check your understanding
Question 1
Name the three properties a function must satisfy to be a vector norm.
Show the step-by-step solution
A norm is positive definite, absolutely homogeneous, and obeys the triangle inequality. Positive definiteness says its value is nonnegative and is zero only at the zero vector. Absolute homogeneity requires . The triangle inequality requires for every pair of vectors.
Question 2
For x = (2, −1, 2), calculate its L₁, L₂, and L-infinity norms. Show the arithmetic.
Show the step-by-step solution
For , add the absolute coordinates: . For , take the square root of the sum of squares: . For , take the largest absolute coordinate, which is . Thus the three values are , , and .
Question 3
Let x = (3, −4). Calculate the three norms of −2x and verify absolute homogeneity for each.
Show the step-by-step solution
First, . Its norm is , which equals . Its norm is . Its norm is . All three match times the original norm, so the negative scalar changes direction without making the size negative.
Question 4
For u = (1, −2) and v = (−3, 1), check the L₁ triangle inequality by computing both sides.
Show the step-by-step solution
Add the vectors first: , so . Separately, and , giving a right side of . Therefore, . This example passes; the coordinate-wise absolute-value inequality explains why every pair passes for .
Question 5
Why is f(x) = (Σᵢ |xᵢ|^(1/2))² not a norm? Test it on (1, 0) and (0, 1).
Show the step-by-step solution
The two coordinate vectors each have . Their sum is , for which
. The triangle inequality would require
, which is false. Thus this function fails one of the required norm
properties. NumPy supports this kind of ord < 1 result for numerical uses,
but its documentation does not call it a mathematical norm.
Question 6
For embeddings = [[3, 4], [6, 8]], what NumPy expression returns one L₂ norm per row, and what are the results?
Show the step-by-step solution
The two rows are separate vectors, so compute along the row’s coordinate
axis: np.linalg.norm(embeddings, ord=2, axis=1). The first result is
; the second is . The output is
[5. 10.]. Setting axis=1 avoids treating the full two-dimensional array as
one matrix norm.
Question 7
For w = (3, −4), calculate the L₁ penalty and squared L₂ penalty when λ = 0.1. Is the squared L₂ quantity itself a norm?
Show the step-by-step solution
The penalty is . The squared penalty is . The squared quantity is not a norm: scaling by multiplies it by , whereas norm homogeneity requires scaling by .
Question 8
The embeddings (3, 4) and (6, 8) have L₂ norms 5 and 10. What can that comparison establish, and what can it not establish about their meanings?
Show the step-by-step solution
It establishes that the second vector has twice the Euclidean magnitude of the first under the given coordinates. The vectors also point in the same direction, because . Their norms alone cannot establish which embedding is more relevant or semantically important; that requires the model’s training context and an appropriate task-specific evaluation.