Vector Spaces
Lecture 1 was tactical: solve . This unit is strategic: we zoom out and map the universe those vectors live in. Six ideas — groups, vector spaces, subspaces, span, independence, basis — and suddenly every ML algorithm is a small geometric story on one board.
The universe upgrade
In Unit 1 you played inside the game: rows, pivots, solutions. Now we ask a question one level up: what kind of world makes those moves legal in the first place? The answer is a vector space — and once you know its rules, "add a gradient step," "average two models," "project onto principal components" all become obviously-allowed moves on the same board.
Nearly every object in ML is a vector in some space: a cat photo is a vector in (150,528 numbers), a word inside a language model is a vector in , your Netflix taste is a vector in some , a layer's weights are a vector in . Training a model is moving through these spaces in clever ways — and you can't reason about a move without knowing the rules of the board.
Decoder ring: how to read ℝ-with-exponents (worth 60 seconds)
| Notation | Shape | Mental picture |
|---|---|---|
| a single number (scalar) | a dot on the number line | |
| a column of numbers | a vector / arrow | |
| an grid | a spreadsheet table | |
| a stack of 3 grids | an RGB image | |
| such stacks | a batch of images |
Read each as "the set of all real-valued data with this shape." is nothing scarier than "a column with 768 numbers in it."
The board-game picture — keep it for the whole unit. A vector space is the board ML plays on. Groups supply the addition rules. Vector spaces add scaling. Subspaces are the legal regions. Independence says which moves are redundant. A basis is the minimal toolkit that reaches every square, and dimension is how big the board really is. Six pieces; the rest of MFML is mostly geometry played with them.
Groups — the bare skeleton of "combining things"
Before we can say what a vector space is, we need the minimum structure under which "combine two things, get a sensible third thing" works. That's a group: a set with an operation such that four promises hold. Closure: stays in — you don't fall out of the set. Associativity: — grouping doesn't matter. Identity: some do-nothing element exists with . Inverse: everything can be undone — each has a partner with . If order also never matters (), the group is Abelian.
Closure and associativity rarely break. The killers are identity and, above all, inverse — sets fail the moment they're missing the negatives, the fractions, or whatever "undo partner" their elements need. Audit the classics yourself:
The counting numbers with zero, , fail to be a group. Which promise breaks?
On the 12-hour clock group, what is the inverse of 5?
Vector spaces = group + scaling
Take an Abelian group of vectors under addition, and bolt on one more power: scaling by real numbers. A real vector space demands: (V1) is an Abelian group — the zero vector is its do-nothing element, its undo. (V2) Distributivity, both ways: and . (V3) Scaling stacks: . (V4) . Translation: a vector space is a place where the two basic moves of linear algebra — add and scale — always make sense and never throw you off the board.
The drawing board. Picture an infinite drawing board with one marked point, . A vector is a movement instruction from the origin. Addition chains movements ("go along , then along "); scaling stretches them ("go 3× as far"). The axioms are simply the guarantee that no matter how you mix these moves, you never fall off the board. That guarantee has a name you met in Unit 1: closure — and it's the reason "add a small gradient to the weights" or "average two models" always yields a valid model of the same shape.
Two examples to hold on to. Lists: with entrywise addition and scaling — three exam scores plus a bonus is , still three scores. Spreadsheets: — whole matrices treated as single vectors, added cell by cell, scaled cell by cell. A weekly-sales sheet plus a corrections sheet is a sheet of the same shape. Same axioms, bigger object.
Don't get attached to the word "vector." In linear algebra it does not mean "column of numbers." It means any element of a vector space. A matrix is a vector. A polynomial is a vector. A function can be a vector. If it adds and scales without leaving its set, it's a vector — that generality is precisely why one theory covers images, sentences, and weight tensors at once.
Is a weight matrix a "vector"?
Subspaces — spaces inside spaces
A flat sheet of glass floats through the corner of your 3-D room, passing through the room's origin. Ants living on the glass experience a complete little 2-D universe: any two of their movements add to a movement on the glass, any scaling stays on the glass. Their world is self-contained — a whole vector space that happens to live inside a bigger one. That's a subspace.
Formally: , , is a subspace of if is itself a vector space under the same operations. The good news: associativity, distributivity and friends are inherited free from — they hold for all of , so certainly on . Only three things can go wrong, and they're all about staying inside:
(S1) — it contains the origin (if not, stop immediately). (S2) closed under adding: . (S3) closed under scaling: — including and negative .
Now stress-test four candidate sets with your own hands — the buttons apply real operations to a sample point and check whether the result stays inside:
In , the only subspaces are flat things through the origin: itself, lines through , planes through , … up to the whole space. Anything shifted off the origin, curved, or bounded will get caught by scaling or adding — somewhere, some operation escapes the set.
Which of these is a subspace of ?
The promised passport: the null space is a subspace
Unit 1 ended with a promise: the blind spot would get its full papers here. Time to deliver. Recall — the directions the machine can't see. Run the three-point test on it:
(S1) , so — the machine maps silence to silence. (S2) if and , then . (S3) . Three for three — for every matrix , no exceptions. The blind spot isn't just a set of unlucky inputs; it is a full flat-through-the-origin world of its own. (Its sibling, the column space — all outputs — is a subspace too, by an equally quick argument. Both officially citizens now.)
And this is why the geometry of Unit 1 looked the way it did: the solution set of was "a flat thing not through the origin" — precisely because it's a subspace (the null space) shifted by . Subspace + shift = affine flat. The vocabulary was waiting for us one unit ahead.
Why does pass the closure-under-addition test?
Span — everywhere you can reach
You're at the origin of a city with a strange transit system: each vector you own is a transport mode — a tram that runs one fixed direction (and backwards, for negative weights, as far as you like). A linear combination is an itinerary. The span is your reachable city: every destination some itinerary can hit. Buy a new tram line that runs along an existing one, and your reachable city doesn't grow by a single block.
Formally, — and it is always a subspace (it contains via all-zero weights, and sums/scalings of itineraries are itineraries). Fly through what spans look like in 3D:
Linear regression's predictions live, by definition, in — the column space you met in Unit 1. PCA compresses by projecting data onto the span of a few top directions. And the famous king − man + woman ≈ queen lives inside the span of four word vectors. "What can this model express?" is usually a question about a span.
Two collinear vectors in (one is times the other). Their span is…
Linear independence — the art of non-redundancy
The span machine kept whispering one idea: some vectors add nothing. Here's the formal detector. Ask: can the vectors cancel each other out — combine to — without every weight being zero?
Yes → linearly dependent. Rearrange that equation and one vector is exposed as a blend of the others — a redundant tram, the "agreeing friend" from Unit 1's group chat. No → linearly independent: the only way to is the boring all-zeros way, and every vector contributes something the rest collectively can't replicate. There is no third option.
Two instant shortcuts. ① If is one of your vectors, the set is dependent on the spot — put weight 1 on , zero elsewhere: a non-trivial combination summing to . ② For non-zero vectors, "dependent" is exactly "at least one is a combination of the others" — redundancy made literal.
A set of five vectors happens to include . What can you conclude?
The detector: elimination hunts redundancy
You never have to guess. The foolproof procedure is one you already own: stack the vectors as columns, run Gaussian elimination, read the pivots. Every column with a pivot is a genuine contributor; every pivot-less column is a blend of the pivot columns to its left — and (this is the beautiful part) in reduced row-echelon form, the entries of a non-pivot column literally spell out its recipe.
Try the presets against the slides: the example exposes column 2 as column 1; the three vectors in come out all-pivots — independent, no redundancy anywhere. Keep the detector in reach; the rest of the unit leans on it twice more.
The recipes theorem — independence survives translation
Your pantry holds trusted, non-redundant ingredients (linearly independent). You cook new dishes , each defined purely by its recipe — how much of each ingredient it uses: . Question: did you accidentally cook the same dish twice under different names? Do you have to taste the dishes — or is reading the recipe cards enough?
Pack the ingredients as columns of and each recipe as a column ; then cooking is a matrix product, . The theorem:
independent independent.
Reading recipe cards is enough. Why? Test the dishes: . But 's columns are independent — the only combination of them that gives is the all-zero one — so forces . The dish-level question collapses onto the recipe-level question, weight for weight. Geometry in the space mirrors geometry among the recipes — that mirror is the entire reason coordinate systems are useful.
Watch the mirror operate — the two panels are different spaces, yet they always agree:
The slides run this at full scale: four dishes from four ingredients with recipe matrix columns , , , . Elimination gives RREF pivots in columns 1–3 and a pivot-less column 4 reading : so , and by the mirror, — the four dishes are dependent, redundancy named exactly. (Feed preset 3 of the detector above and read it off yourself.)
Someone hands you 50 word-embedding vectors that live in a 32-dimensional space. Independent or not?
Basis — the just-right toolkit
You're at the origin of a flat city and want to reach every address by chaining straight walks. Knowing only north: you cover one avenue — not enough. North + east: the whole city — a generating set. North + east + north-east: still the whole city, but the third direction is a blend of the first two — generating, yet wasteful. North + east, nothing more: reaches everything, wastes nothing. That is a basis: a linearly independent generating set — the smallest toolkit that still reaches every square.
Four portraits of the same object, all provably equivalent: a basis is ① a generating set that's independent (the textbook line); ② a minimal generating set — remove any vector and some part of the space becomes unreachable; ③ a maximal independent set — add any vector and redundancy appears; ④ a unique address book — every has exactly one recipe . The fourth is the money view. Why unique? Two recipes for the same would subtract to a non-trivial combination — forbidden by independence. No redundancy in the toolkit ⟺ no ambiguity in the addresses.
And a basis is thoroughly non-unique — is happy with the canonical , or the staircase , or any three independent vectors whatsoever. Same space, different address books:
PCA is "find a new basis for the data, ordered by variance." The Fourier transform is "re-express the signal in the basis of sines and cosines." Autoencoders learn a basis where structure becomes obvious. The data never changes — the address book does, and in the right book the pattern you're hunting becomes a one-liner. Choosing bases well is much of the art of representation learning.
Three linearly independent vectors in . Do they form a basis of ?
Dimension — how big is the board, really?
Here is a small miracle you can lean on forever: pick any basis of a space and count its vectors; pick a completely different basis and count again — you always get the same number. (If a 3-vector basis and a 4-vector basis coexisted, the recipes theorem's pigeonhole would convict the larger one of redundancy — contradiction.) That invariant count is the dimension, : the number of independent directions the space truly has. So , and — a basis for matrix-space is the family of one-hot matrices , one per cell. For subspaces: , with equality only when is .
Take . Every vector in it has 2 components, but the space is a line: . Components count the ambient space you're written in; dimension counts the intrinsic space you actually occupy. A road on a 2-D map is a 1-D world ("how far along?"). ML has a name for this gap — intrinsic dimensionality — and a famous bet about it, the manifold hypothesis: real data (faces, speech, text) tends to occupy a low-dimensional surface curled inside its huge ambient space. Representation learning is largely the hunt for that small true dimension.
. What is ?
Finding a basis — the algorithm
Handed a pile of vectors that span some subspace , how do you shrink the pile to a basis? Three steps you can now guess: ① stack them as columns of ; ② row-reduce to echelon form; ③ keep the original vectors sitting over the pivot columns. Those survivors are independent (pivots certify it), and they span everything the pile spanned (each discarded vector is a recipe of survivors — the RREF column says exactly which recipe). Basis found; count it and you've measured too.
The basis is the original pivot columns of , not the tidy columns of the reduced matrix. Row operations scramble what each column looks like while preserving which subsets of columns are independent — so reduction is the X-ray that tells you which bones to keep; the bones themselves come from the original skeleton.
The slide example, finished honestly. Four vectors spanning :
Stack, reduce (or press preset 4 in the detector of Section 8 and watch it happen):
Pivots in columns 1, 2 and 4. Column 3 is the only freeloader, and its RREF entries name the recipe: (check it — it works on all five components). So:
A basis of is and : a 3-D flat through the origin of . Four vectors walked in; one was a blend; three genuine directions remain. (Note for companion-PDF readers: the companion's version of this example reports basis , , via — but that combination misses 's fourth component (). The numbers above are machine-verified; x₄ earns its pivot.)
One more from the slides, in the other direction: the three vectors in reduce to all-pivots — independent — yet they are not a basis of : three trams can't cover a four-dimensional city. Independent ≠ basis until the count matches the dimension.
The whole story, in six lines
① A group is combining-with-guarantees; add scaling and you get a vector space — the board every ML object lives on. ② A subspace is a flat world through the origin inside a bigger one — null space and column space are the star citizens. ③ The span is everywhere your vectors can reach; it never grows when you add a redundant vector. ④ Independence is non-redundancy, and elimination's pivots detect it mechanically. ⑤ A basis is span + independence: the smallest toolkit reaching everything, giving every vector exactly one address. ⑥ Dimension — the size of any basis — is the board's true size, and it polices everything: more vectors than dimensions ⇒ redundancy, guaranteed.
Four questions to run on any vector or matrix you meet in ML: What space does it live in? Is this set independent or redundant? What's the span / column space / null space? Is there a smarter basis? That loop is most of the geometric reasoning behind classical ML — and a surprising amount of deep learning.
Take these home — the companion's five practice problems (with answer keys)
P1. Which are subspaces of ? (a) (b) (c) (d) . Key: (a) and (d) — flat, through the origin. (b) misses 0; (c) dies under λ = −1.
P2. Express in terms of . Key: row-reduce : unique solution .
P3. independent; . Independent? Key: check the recipes — three pivots, independent. The mirror does the rest; the never had to be seen.
P4. Is a basis of ? Key: row-reduce → 3 pivots, independent; and 3 independent vectors in a 3-D space automatically span it. Yes — both arguments in one breath.
P5. Basis and dimension of . Key: pivots in columns 1 and 3 — , . Basis , dimension 2. (Preset 5 in the detector.)