Foundations · 4
Norms, distance & projection
A norm turns a vector into a single length. From it come distance (the norm of a difference), unit vectors (divide by the norm), and projection (how much of one vector lies along another).
The L2 norm is length
v.norm() is the square root of the sum of squares — the straight-line length of the vector from the origin.
Distance is the norm of the difference
The distance between two points is ‖a − b‖. Same operation, one subtraction first.
Projection
The scalar projection of a onto b is a·b / ‖b‖ — how far along b's direction a reaches. Against a unit axis it is just that coordinate.
Seeing distance: the pairwise matrix
Take four points and measure every point-to-point distance — ‖P_i − P_j‖, built with broadcasting. The diagonal is dark (a point is distance 0 from itself); the far-apart pairs are bright.
Your turn: make a unit vector
A unit vector points the same way but has length 1. Divide v by its own norm so that ‖u‖ = 1.
What to remember
- The L2
normis a vector's length, the square root of the sum of squares. - Distance between two points is the norm of their difference,
‖a − b‖. - A unit vector is
vdivided by its norm; the projection ofaontobisa·b / ‖b‖. - In borch:
v.norm(),a.sub(b).norm().