A vector is one of the most useful ideas in all of AI, and it quietly wears two faces at once. To a programmer, a vector is just an ordered list of numbers, something like [2, 1] that you would store in an array or a NumPy ndarray. To a geometer, that same list is an arrow pointing from the origin to a spot in space, with a direction and a length (its magnitude). Both descriptions are the same object seen from different angles, and fluently switching between "list of numbers" and "arrow in space" is the core skill this lesson builds. Nearly every AI system, from a spam filter to a large language model, runs on this dual idea.
Two ways to see the same vector
The order of the numbers matters: [2, 1] and [1, 2] are different vectors, because each slot (each component) means something specific. The number of components is the vector's dimension.
View
What it is
Example
List of numbers
An ordered tuple of components
v=
Ask the tutor
Ask about this lesson, or about anything in AI. Answers cite the lessons they draw on.
Finished this lesson?
Mark it complete to earn XP, keep your streak, and schedule a review.
[1,3]
Arrow in space
Direction plus magnitude from the origin
up-and-right, length 10
In 2D or 3D you can literally draw the arrow. In the 768- or 1536-dimensional spaces used for embeddings you cannot picture it, but the same rules apply, which is exactly why the algebra matters more than the drawing.
Adding vectors and scaling them
Two operations define almost everything you do with vectors.
Addition works component by component: line the vectors up and add matching slots. Geometrically, you place the tail of one arrow at the head of the other.
Scalar multiplication multiplies every component by a single number (a scalar). A scalar of 2 doubles the arrow's length; a scalar of −1 flips it to point the opposite way.
The magnitude (length) of a vector comes straight from Pythagoras:
∥v∥=∑ivi2
Worked example: numbers you can check
Let u=[2,1] and v=[1,3].
1Add component-wiseu + v = [2+1, 1+3] = [3, 4]. Only matching slots combine: first component with first, second with second.
2Scale by a scalar2v = 2 × [1, 3] = [2, 6]. Every component is multiplied by 2, doubling the arrow's length while keeping its direction.
3Measure the lengthThe sum [3, 4] has magnitude sqrt(3² + 4²) = sqrt(9 + 16) = sqrt(25) = 5, a clean whole number.
So u+v=[3,4], 2v=[2,6], and ∥[3,4]∥=32+42=25=5.
Vector spaces, basis, and dimension
A vector space is simply the full set of vectors you can build from a starting set using addition and scalar multiplication, and the result always stays inside the space (add two 2D vectors, get another 2D vector). A basis is a minimal set of vectors whose combinations reach every point in the space. In 2D the standard basis is e1=[1,0] and e2=[0,1]; any vector such as [3,4] is just 3e1+4e2. The dimension is the number of vectors in that basis, how many independent directions the space has.
Why AI turns everything into vectors
Machines do arithmetic, not meaning, so AI encodes data as vectors of numbers:
Feature vectors: a house becomes [bedrooms,area,price]; an image becomes a long vector of pixel values.
Embeddings: a word, sentence, or product is mapped to a dense vector so that closeness in space means similarity in meaning. "cat" and "kitten" land near each other; "cat" and "invoice" land far apart.
Once data lives in a vector space, similarity becomes distance, search becomes finding nearby arrows, and learning becomes nudging vectors around, all built from the two operations above.
Common mistakes
Adding vectors of different sizes. You can only add vectors with the same number of components; [1,2] and [1,2,3] cannot be added.
Ignoring order.[2,1] is not the same vector as [1,2], each position carries its own meaning.
Confusing dimension with magnitude. The vector [3,4] has dimension 2 (two components) but length 5. They are unrelated numbers.
Assuming scaling rotates the arrow. Scalar multiplication only stretches or shrinks along the same line; a negative scalar reverses direction but does not turn it to a new angle.