II.3 · Linear Algebra
How do you keep direction and remove length?
A norm turns a vector into a nonnegative size. Divide a nonzero vector by its Euclidean norm to retain only its direction, and compare how three norms define different unit balls.
Length, unit direction, and three unit balls
The normalized arrow has length 1 and keeps the direction of v. Diamond = L₁ unit ball; circle = L₂; square = L∞. These are three different meanings of distance.
- original vector
- (3, 4)
- Euclidean length
- 5
- taxicab length
- 7
- largest component magnitude
- 4
- unit vector (exact expression)
- (3 / (5), 4 / (5))
- unit x-component
- 3 / (5)0.600000
- unit y-component
- 4 / (5)0.800000
- unit length
- 1
Exact expressions use =. Rounded computations use ≈. All arrows use these same quantities.
The normalized arrow has length 1 and keeps the direction of v. Diamond = L₁ unit ball; circle = L₂; square = L∞. These are three different meanings of distance.
from −4 to 4, up to 2 decimal places
from −4 to 4, up to 2 decimal places
Try , then , then zero. Predict which quantities remain defined at zero. The three length measures all become zero, while the unit-vector rows disappear into an explicit exception. Moving the tip away from zero restores a unit direction.
Intuition: size depends on what you measure
Euclidean length measures a straight move. Taxicab length counts the total travel along the two coordinate axes. The largest-component norm measures the worst coordinate displacement. These answer different questions about the same vector. None depends on which quadrant contains it, because signs describe direction rather than size.
Normalization removes Euclidean length without changing a nonzero vector’s direction. A short vector and a long vector along the same ray give the same normalized arrow. A vector on the opposite ray gives the negative unit vector. The unit circle acts as a catalogue of possible directions.
Definition
For ,
An unqualified norm in this block means the Euclidean norm. A unit vector has Euclidean norm . The normalized vector is defined only for :
A norm is nonnegative, vanishes only at zero, scales by the absolute value of a scalar, and satisfies the triangle inequality . For Euclidean distance, the straight route is no longer than the route through an intermediate point. Equality occurs for moves along the same ray, including a zero move.
Mechanics: the three unit balls
The unit ball of a norm consists of vectors whose norm is at most . The stage draws its boundary. For , gives the diamond. For , gives the square. For , gives the circle. These shapes follow directly from the norm definitions, rather than from the current vector’s length.
At the norms are , , and , respectively. The point lies on the square boundary, outside the Euclidean circle, and outside the diamond. If you divide by instead, the resulting vector lands on the diamond; it generally is not a Euclidean unit vector.
Derivation: why the normalized length is one
The length is positive when the vector is nonzero. Apply the scaling law from II.2 Scalar multiplication:
The scaling factor is positive, so the direction is preserved. At zero the factor would be , and this derivation cannot begin. A zero result is not a substitute: its norm is , not .
The component inequalities also compare the three norms:
The first follows because the sum of squares contains the square of the larger component. For the second, ; taking nonnegative square roots preserves the inequality. Both become equalities on an axis. The ordering does not make one norm universally better; each defines a different size measure.
Worked examples
For the Euclidean length is . Normalization gives , whose squared length is . The other norms are and .
Inspect the worked calculation
For v = (3, 4), the squared length is 9 + 16 = 25, so the length is 5.
- original vector
- (3, 4)
- Euclidean length
- 5
- taxicab length
- 7
- largest component magnitude
- 4
- unit vector (exact expression)
- (3 / (5), 4 / (5))
- unit x-component
- 3 / (5)0.600000
- unit y-component
- 4 / (5)0.800000
- unit length
- 1
For the normalized vector is . Those expressions are exact. Decimal components such as are approximations; squaring rounded display values is not an exact proof of unit length. The inspector separates exact component expressions from their numerical approximations.
Executable reference code
The code distinguishes computing a norm from computing a unit direction. The latter rescales first. The NumPy version checks both shape and finiteness, rejects zero, and uses the same bounded rescaling idea.
from math import hypot, isfinite
def norms(v):
if len(v) != 2 or not all(isfinite(x) for x in v):
raise ValueError('Expected two finite components')
x, y = v
return hypot(x, y), abs(x) + abs(y), max(abs(x), abs(y))
def normalize(v):
_, _, m = norms(v)
if m == 0:
raise ValueError('Zero has no unit direction')
x, y = v[0] / m, v[1] / m
h = hypot(x, y)
return x / h, y / h
if __name__ == '__main__':
assert norms((-3, 4)) == (5, 7, 4)
assert normalize((3, 4)) == (0.6, 0.8)
assert hypot(*normalize((1.7e308, 1.7e308))) > 0.999999999999999import numpy as np
def normalize(v):
v = np.asarray(v, dtype=float)
if v.shape != (2,) or not np.isfinite(v).all():
raise ValueError('Expected a finite two-component vector')
m = np.max(np.abs(v))
if m == 0:
raise ValueError('Zero has no unit direction')
scaled = v / m
return scaled / np.hypot(*scaled)
v = np.array([-3.0, 4.0])
l2 = np.hypot(*v) # avoids squaring overflow; a truly huge norm can still overflow
l1 = np.sum(np.abs(v))
linf = np.max(np.abs(v))
assert (l2, l1, linf) == (5, 7, 4)
assert np.allclose(normalize(v), [-0.6, 0.8])Explore
Compare with : predict the unchanged normalized vector. Reverse both signs and predict the new unit vector. On the horizontal axis, compare all three norms. Move along the diagonal and explain why the three readouts differ even though there is only one arrow. Try zero last, and identify which definition fails.
Common mistakes
Dividing by the squared norm is generally wrong: has length . Dividing each component by its own magnitude gives a sign pattern, not a unit direction. Adding a tiny constant to the denominator can avoid a software exception but changes the formula and produces lengths below ; such regularization needs its own explicit purpose and definition.
Numerical considerations
Squaring first can overflow or underflow even when a meaningful unit direction exists. For finite , set and . At least one scaled component has magnitude , and neither exceeds . Then normalize by its bounded length. This works for enormous inputs and for a pair of smallest subnormal components. The real norm itself may exceed the largest finite binary64 value; direction can still be representable.
Engineering and ML connections
Unit directions separate where a motion goes from how far it travels. Different norms measure different costs: total coordinate movement, Euclidean displacement, or a worst coordinate limit. Feature normalization can reduce the influence of overall scale in a similarity calculation, but discarding magnitude also discards information. Choose it because the task needs direction, rather than because every vector should have unit length.
Exercises
Summary and checkpoints
A norm defines size, and Euclidean normalization retains the direction of a nonzero vector with unit length. Check that you can explain the three unit-ball shapes, derive the unit-length property, reject zero, and rescale before dangerous arithmetic. II.4 Dot product compares two directions with a dot product.