A grid of numbers
A matrix is a rectangular grid of numbers arranged in rows and columns. We say a matrix is m-by-n when it has m rows and n columns — rows first, columns second, always. The matrix below is 2-by-3: two rows, three columns.
A = [[1, 2, 3],
[4, 5, 6]] <- 2 rows, 3 columns (2-by-3)Three ways to read it
Reading 1 — a data table. Rows are records, columns are features. Three students, two test scores each: it is just a spreadsheet with the borders erased.
Reading 2 — a list of column [[vector|vectors]]. Slice the grid into vertical strips. Each column is a vector, and the matrix is those vectors standing side by side. This is the reading we lean on most.
Reading 3 — a machine. Feed the matrix a vector and it hands you back a new vector. In this reading a matrix is a *function*: numbers go in, numbers come out. The whole next guide lives here.
Flipping it: the transpose
The transpose, written A^T, flips a matrix across its diagonal: rows become columns and columns become rows. A 2-by-3 matrix becomes 3-by-2. It is the cleanest way to turn "list of columns" into "list of rows" without losing a single number.
A = [[1,2,3], A^T = [[1,4],
[4,5,6]] [2,5],
[3,6]]