Linear algebra is continuous rather than discrete mathematics, so many computer scientists arrive with little experience of it — yet it is essential for nearly every machine learning algorithm, deep learning above all. This chapter teaches exactly the prerequisites the book needs.
Aside — how to read this chapter
Already comfortable? Skip ahead. Need a formula reference later? The book recommends The Matrix Cookbook (Petersen & Pedersen, 2006). Never seen linear algebra? This teaches enough to read the book, but a dedicated text (e.g. Shilov, 1977) is recommended too. Many standard topics are deliberately omitted as inessential for deep learning.
§2.1 The four objects
The typography IS the type system — see the notation page.
- A scalar scalar A single number, written in italics (s ∈ ℝ), in contrast to the arrays of linear algebra. defined in ch. 2 — open in glossary is a single number, italic lowercase, introduced with its kind: “let be the slope,” “let be the number of units.”
- A vector vector An ordered 1-D array of numbers, written bold lowercase (x ∈ ℝⁿ); a point in space, one coordinate per axis. defined in ch. 2 — open in glossary is an ordered array; element is . With real elements, — a point in -dimensional space, one coordinate per axis. Written as a column: . Index a set of elements with a subscript set: for , picks those three; a minus sign takes complements ( = all but ).
- A matrix matrix A 2-D array of numbers, bold uppercase (A ∈ ℝ^{m×n}); A_{i,:} is row i, A_{:,i} column i. defined in ch. 2 — open in glossary is a 2-D array, ; is the top-left entry, row , column ; for expressions, indexes the result.
- A tensor tensor An array with any number of axes on a regular grid, written sans-serif bold. defined in ch. 2 — open in glossary generalizes to any number of axes; element of 3-D tensor is .
The transpose transpose Mirror of a matrix across its main diagonal: (Aᵀ)_{i,j} = A_{j,i}. defined in ch. 2 — open in glossary mirrors a matrix across its main diagonal: (fig 2.1):
Fig 2.1 (recreated) — entries on the main diagonal (amber) stay put; everything else reflects. A vector is a one-column matrix, so its transpose is a row: ; a scalar is its own transpose.
Element-wise arithmetic works as expected: same-shape addition (), scalar multiply/add (). Deep learning adds one unconventional shorthand — broadcasting broadcasting DL shorthand: C = A + b adds vector b to every row of A — implicit copying. defined in ch. 2 — open in glossary : means , i.e. the vector is implicitly copied into every row rather than materializing that copy.
§2.2 Multiplying matrices and vectors
The matrix product matrix product C = AB with C_{i,j} = Σₖ A_{i,k}B_{k,j}; each entry is a row·column dot product; not commutative. defined in ch. 2 — open in glossary requires the inner shapes to agree — must have as many columns as has rows:
Term by term
| left factor — its ROW i is consumed | m×n | |
| right factor — its COLUMN j is consumed | n×p | |
| the shared inner dimension being summed away | 1…n | |
| one entry of the result: the dot product of row i with column j | scalar; C is m×p |
What this really says
Every entry of the product is a similarity score: how much row of and column of point in the same direction. The inner dimension is “summed away” — which is why shapes chain like dominoes: .
Step through it with real numbers:
C1,1 = row 1 · column 1 = 1·2 + 2·0 + 0·4 = 2
This is not element-wise multiplication — that operation exists too and is called the Hadamard product hadamard product Element-wise matrix product A⊙B, distinct from the standard matrix product. defined in ch. 2 — open in glossary . The dot product dot product xᵀy — matrix product of two same-length vectors; equals ‖x‖‖y‖cos θ. defined in ch. 2 — open in glossary between same-length vectors is the matrix product — so the matrix product computes as the dot product of row of with column of .
Useful properties (a deliberately partial list):
- distributive:
- associative:
- not commutative in general ( does not always hold) — though the vector dot product is:
- transpose of a product reverses the order:
That last rule proves dot-product commutativity in one line: a scalar is its own transpose, so .
We can now write a whole system of linear equations in three symbols:
Term by term
| KNOWN coefficient matrix — row i holds the coefficients of equation i | m×n | |
| UNKNOWN vector we solve for | n×1 | |
| KNOWN right-hand side — element i is the target of equation i | m×1 |
Expanded, row by row, it is exactly the school system: , and so on down to row — the matrix-vector notation is simply more compact.
§2.3 Identity and inverse
The identity matrix identity matrix Iₙ: ones on the main diagonal, zeros elsewhere; Iₙx = x for all x. defined in ch. 2 — open in glossary changes nothing: — ones on the main diagonal, zeros elsewhere (fig 2.2 is just ). The matrix inverse matrix inverse A⁻¹ with A⁻¹A = I; solves Ax = b analytically as x = A⁻¹b — a theoretical tool, not a numerical one. defined in ch. 2 — open in glossary is the matrix that undoes : . It solves the linear system in four mechanical steps:
Worked example — invert and solve
Let , . For a 2×2, with . So . Check: ✓ and ✓.
Aside — why nobody actually computes A⁻¹
is mainly a theoretical tool. On a digital computer it is stored with limited precision, and algorithms that work directly from (chapter 4’s territory) usually give more accurate estimates of .
§2.4 When does a solution exist? Span and independence
Think of the columns of as directions you can travel from the origin, with saying how far to go along column :
Term by term
| column i — one available direction of travel | m×1 | |
| how far to travel along that direction (can be negative) | scalar | |
| the destination reached — a linear combination of the columns | m×1 |
A linear combination linear combination Σᵢ cᵢ v⁽ⁱ⁾ — scale each vector by a coefficient and add. defined in ch. 2 — open in glossary of vectors is ; the span span All points reachable by linear combination of a set of vectors; the span of A's columns = its column space. defined in ch. 2 — open in glossary is everything reachable that way. Solving asks: is in the span of the columns (the column space, or range, of )? Try it:
det(A) = 3.75
solutions of Ax = b: 1 (unique)
x = [1.00, 1.00]ᵀ
b = 1.00·a₁ + 1.00·a₂
Columns are linearly independent: the span is all of ℝ², A is invertible, and the dashed path shows x₁a₁ then x₂a₂ reaching b.
The counting rules the widget demonstrates:
- Solutions come in 0, 1, or ∞ — never “exactly two”: if and both work, every blend works too.
- Solvable for every ⟺ the column space is all of ⟺ the columns include a set of exactly linearly independent linear independence No vector in the set is a linear combination of the others; redundant vectors add nothing to the span. defined in ch. 2 — open in glossary vectors ( is necessary but NOT sufficient — two identical columns of a 2×2 span only a line). No -dimensional set has more than mutually independent vectors.
- Invertibility additionally needs at most one solution per : at most columns. Together: must be square () with all columns independent. A square matrix with dependent columns is singular singular matrix A square matrix with linearly dependent columns; not invertible; equivalently, some eigenvalue is zero. defined in ch. 2 — open in glossary — no inverse (though the system may still be solvable by other means).
- For square matrices the left and right inverse coincide: .
Check yourself — objects, products, inverses, span
1.A is 4×3 and B is 3×5. Which products are defined, and with what shape?
2.In the MatrixGrid widget with A = [[1,2,0],[-1,3,1]] and B = [[2,1],[0,1],[4,-2]], predict C₂,₂ before stepping to it.
3.Which identity is FALSE in general?
4.In the VectorSpanLab, you drag a₂ until it lies exactly along a₁. What happens and why?
5.Why does the book call A⁻¹ 'primarily a theoretical tool'?