Skip to content

Linear Algebra

Vectors and vector spaces

Arrows and lists: one object, two faces

An arrow you can add and stretch, and a list of numbers you can compute with: the same object wearing two hats. Master this and every embedding in the LLM path stops being magic.

A is the rare idea that is simultaneously visual and numerical. Draw it as an arrow from the origin and you can add arrows tip-to-tail and stretch them. Write it as a column of numbers and a computer can do the exact same operations with plain arithmetic. Those two pictures never disagree, and that agreement is the whole engine of machine learning.

One object, two faces

An arrow in the plane is pinned down by two numbers: how far right and how far up its tip sits. So we write it as a column, its coordinates.

The arrow is the intuition; the list is what you type.

Everything below is just: what happens to the arrow, and what happens to the list, checking that they always match.

Why the origin matters

Every vector starts at the same place, the origin . That is what lets us treat an arrow as pure direction and length, ignoring where it "is". Two arrows with the same length and heading are the same vector, no matter where you draw them. Coordinates just measure the tip once the tail is nailed to the origin.

Adding and scaling, the only two moves

A vector space allows exactly two operations, and everything is built from them. Addition is tip-to-tail: slide so its tail sits on the tip of ; the arrow from the origin to where you land is the sum. In coordinates you add componentwise. Scalar multiplication stretches, or with a negative number flips, an arrow without turning it.

Combine both moves and you get a , the star of this lesson: . Pick two knobs and , scale each arrow, add them tip-to-tail, and see where you land. The demo below is that expression, made draggable.

Drag the tips of v and w. Slide the coefficients a and b, or toggle the span.
v (drag tip)w (drag tip)a·v + b·w
v = (2, 1)w = (-1, 2)a·v + b·w = (1.00, 3.00)det = 5.00independent, spans the plane
Toggle show span to shade every reachable point.

That shaded plane is the span

As long as and point in genuinely different directions, sweeping and across all real numbers lets the green tip visit every point in the plane. That reachable set is the span of the pair. Drag until it lines up with and the shading snaps from a full plane down to a single line: two arrows on the same line are redundant.

Span, basis, dimension

The span of a set of vectors is every linear combination you can build from them.

When neither vector is a scaled copy of the other, we call them , and a quick test in 2-D is that the determinant is nonzero.

Two independent vectors that span the whole plane form a : a minimal toolkit where every point has exactly one address . The number of vectors in a basis is the dimension. The plane is 2-D because it takes exactly two; make them parallel and you drop to a 1-D span, a line.

Why parallel means redundant

If for some number , then any combination collapses: . The two knobs fold into a single knob, so you can only ever produce scaled copies of , a line through the origin. That is exactly the determinant going to zero.

The punchline: it is all vectors

A row of a spreadsheet (age, height, income) is a vector. A pixel's (R, G, B) is a vector. A word embedding, the numbers an LLM assigns to "king", is a vector, just with 300 or 12,288 components instead of 2. The 2-D arrows you just dragged are the honest, visible shadow of those high-dimensional objects. Adding and scaling still mean the same thing up there, you just cannot draw it.

A vector is literally a list, and add and scale are three lines each.

# a vector is just a list of numbers
v = [2, 1]
w = [-1, 2]

def add(u, x):        # tip-to-tail addition
    return [u[i] + x[i] for i in range(len(u))]

def scale(a, x):      # stretch or flip
    return [a * c for c in x]

# linear combination a*v + b*w with a = 1.5, b = -0.5
combo = add(scale(1.5, v), scale(-0.5, w))   # -> [3.5, 0.5]

# a word embedding is the SAME object, just longer:
king = [0.21, -0.44, 0.05]   # imagine 300 numbers = one point in 300-D
A word embedding is the same object, just longer.

Check yourself

Two arrows in the plane that do not lie on the same line can, by choosing a and b, reach:

Making w a scalar multiple of v (so they are parallel) forces their span to:

What does it mean that {v, w} is a basis for the 2-D plane?

Tie together independence, span, and dimension. Try to state it, then check.

Lock it in

  • A vector is one object with two faces: an arrow and a list of numbers.
  • Add and scale are the only two moves; everything is a linear combination.
  • Span is everything a set can reach; independence keeps it from collapsing.
  • A word embedding is this same object in hundreds of dimensions.

Primary source

For the definitive visual build-up, watch 3Blue1Brown, Essence of Linear Algebra, chapters 1 to 3. To drag vectors in the page yourself, the free interactive textbook Immersive Linear Algebra covers exactly this.

Where this reappears

Every embedding lives in a vector space just like the plane you dragged, only with hundreds of axes. The famous "king minus man plus woman is about queen" result is literally the vector addition on this page, done in high dimensions.