A vector is both an ordered list of numbers and a move through space. Read those views as one object, then measure length, distance and direction without losing track of the coordinates.
Every observation a model receives eventually becomes a vector. This lesson starts with the thing itself: ordered coordinates, drawn as movement on a plane.
Six ideas connect the algebra to the picture, with short challenges for reading arrows, combining and scaling them, measuring norms and distances, and separating direction from length.
Every board connects the same vector in two forms: ordered components and geometry on a plane. The answers are computed from the coordinates. There is no timer -- read the movement before doing the arithmetic.
This lesson
0 of 6 challenges cleared
1 of 6
A vector is a list and an arrow
The same ordered numbers can describe one observation or one displacement.
A vector is an ordered list of numbers. In a dataset, those numbers might be the features of one example. In a plane, (3, 2) means move three units right and two up, so it draws an arrow from the origin to (3, 2).
Order matters: (3, 2) and (2, 3) are different vectors. The number of coordinates is the vector's dimension. A vector with d coordinates is represented in NumPy by shape (d,).
A row such as [height, weight, age] is a three-dimensional vector even though nobody draws it. Geometry is still the useful language: nearby rows describe similar observations.
Challenge
Read the Arrow
1 of 3
Move between the picture and its ordered components.
Read horizontal movement first and vertical movement second. The arrow is the same vector wherever it is drawn.
2 of 6
Coordinates describe displacement
Subtract the start from the finish, coordinate by coordinate.
An arrow does not have to start at the origin. From p = (1, 2) to q = (4, 6), the displacement is q - p = (3, 4). The same vector can be moved anywhere without changing its length or direction.
This is why points and vectors use the same pair of numbers but answer different questions. A point says where; a vector says how far and which way.
Subtract in the correct order. Reversing the trip gives p - q = (-3, -4): the same length, exactly the opposite direction.
3 of 6
Add steps; scale directions
Addition joins displacements, while a scalar changes an arrow's length and sign.
Vector addition is coordinatewise: (2, 1) + (1, 3) = (3, 4). Geometrically, take the first step and then the second. The arrow from the original start to the final point is their sum.
Multiplying by a scalar scales every coordinate. Positive values keep the direction, values between zero and one shorten it, zero collapses it to the origin, and a negative value reverses it.
-2(1, -3) = (-2, 6). Both coordinates are multiplied; changing only one coordinate changes the direction and is not scalar multiplication.
Challenge
Join the Moves
1 of 3
Add or subtract vectors one coordinate at a time.
Keep first coordinates with first coordinates and second with second. The resultant arrow appears after you commit.
Challenge
Scale It
1 of 4
Choose the scalar that lands exactly on the target.
Move the dial. Watch length and direction change together.
4 of 6
A norm turns an arrow into a length
Square the coordinates, add them, and take the square root.
The Euclidean or L2 norm is ||v||₂ = sqrt(v₁² + ... + v_d²). It is Pythagoras in any number of dimensions. The vector goes in; one non-negative number comes out.
Squaring means signs do not affect length. The vectors (3, 4), (-3, 4), and (3, -4) all have norm 5.
When you only need to compare lengths, compare squared norms. 3² + 4² and 4² + 4² have the same ordering as their square roots and avoid unnecessary arithmetic.
Challenge
Measure the Arrow
1 of 3
Turn components into Euclidean length.
Square, add, then take the square root. The answer is a scalar.
5 of 6
Distance is the norm of a difference
Turn two points into a displacement, then measure it.
The distance between x and y is ||x - y||₂. Subtraction moves one point to the origin; the norm measures the remaining arrow.
Nearest-neighbor methods use exactly this idea. A new example becomes a vector, its distance to stored examples is measured, and the closest examples vote. Feature scale matters: a coordinate measured in thousands can drown out one measured between zero and one.
For choosing the nearest point, squared distance is enough. The square root changes the units but never changes which candidate is smallest.
Challenge
Nearest Point
1 of 3
Choose the nearest candidate without approximating square roots.
Subtract each point from the query and compare squared distances.
6 of 6
Normalization keeps direction and removes length
Divide a nonzero vector by its norm to make a unit vector.
A unit vector has norm 1. For nonzero v, the vector v / ||v||₂ points in the same direction and has unit length. This separates the question which way? from how much?.
The zero vector is the exception. Its norm is zero, so normalization would divide by zero. Production code must decide what that case means rather than letting it pass unnoticed.
(3, 4) / 5 = (3/5, 4/5). Squaring the new coordinates gives 9/25 + 16/25 = 1, so its norm is exactly one.
Challenge
Keep the Direction
1 of 3
Choose the unit vector pointing the same way.
Divide every coordinate by the vector norm. Watch for the zero vector.