Wiki
Core12 min read

Matrices: transformations and data

A matrix is a linear map — it moves the whole space at once — and its columns are where the basis vectors land.

A spreadsheet of students against subjects is a matrix. So is the weight table of a neural network layer, the covariance of a dataset, and a grayscale image. All of these really are just rectangular arrays of numbers, but the reading that unlocks linear algebra is different: a matrix is a function that takes a vector in and returns a vector out, moving the entire space at once.

A matrix is a verb, not a noun

The entries are not the point — the action is. A 2×22\times 2 matrix bends, stretches, rotates and flips the plane. If you know where it sends the two basis vectors, you know where it sends every vector, because everything is a combination of those two.

Drag the four entries below and watch the grid deform. The two solid arrows are the columns — the destinations of the basis vectors (1,0)(1,0) and (0,1)(0,1).

Move the four entries — the grid is the matrix

det M
1.44
area scale
1.44×
M·(1,0)
(1.0, -0.4)
M·(0,1)
(0.6, 1.2)

det > 0 — area is scaled by det, orientation preserved.

The two solid arrows are the columns of the matrix — where the basis vectors land. Because every point is a linear combination of them, knowing where the basis goes tells you where everything goes. The tinted square is the image of the unit square; its area is |det M|, which is why a zero determinant means information was destroyed, not merely rearranged.

The two readings of a matrix

A matrix A∈Rm×nA \in \mathbb{R}^{m\times n} can be read two ways, and fluency means being able to switch between them:

  • Rows as measurements. Each of the mm rows is a weighting of the nn inputs. Multiplying AxA x computes mm inner products — a score per row. This is the reading of a classifier: row ii scores how much the input looks like class ii.
  • Columns as directions. The nn columns are vectors in Rm\mathbb{R}^m. The product AxA x is a weighted sum of those columns, with weights x1,…,xnx_1, \dots, x_n. This is the reading that explains span and rank.

Ax=x1 a:,1+x2 a:,2+⋯+xn a:,n.A x = x_1\, a_{:,1} + x_2\, a_{:,2} + \cdots + x_n\, a_{:,n}.

The matrix–vector product costs O(mn)O(mn): mm dot products, each over nn entries. A matrix–matrix product ABAB costs O(mnk)O(mnk) because each of the kk columns of BB is transformed separately — composition is just applying two maps in sequence.

Rank, span, and the column space

The set of all outputs AxA x as xx ranges over every input is the column space (or range) of AA. Its dimension is the rank. Rank is the amount of genuinely independent information the map can carry:

  • An m×nm\times n matrix has rank at most min⁡(m,n)\min(m, n).
  • Rank =n= n means distinct inputs give distinct outputs (the columns are independent; no information is collapsed).
  • Rank <n< n means some non-zero xx is sent to zero. That input is in the null space, and it is unrecoverable.

This is why a determinant of zero matters. The determinant is the signed area (or volume) by which the map scales space; zero means the whole plane has been squashed onto a line. Volumes collapse, inverse maps stop existing, and a model built on such a matrix is not identifying its parameters.

Shapes are a contract

AxA x only makes sense when the number of columns of AA equals the number of entries of xx. In code this is where most shape bugs come from: an (m,n)(m, n) matrix times a length-nn vector is a length-mm vector, and (m,k)(k,n)=(m,n)(m, k)(k, n) = (m, n). Write the shapes down before you write the expression.

Special matrices worth recognizing

  • Identity II — leaves every vector unchanged; the map that does nothing.
  • Diagonal — stretches each axis independently; cheap to invert and multiply.
  • Symmetric A=A⊤A = A^\top — the eigenvectors come out perpendicular with real eigenvalues, which is why covariance matrices are so well behaved.
  • Orthogonal Q⊤Q=IQ^\top Q = I — a rotation or reflection; it preserves lengths and angles, so it never amplifies error.
  • Positive definite — for every non-zero xx, x⊤Ax>0x^\top A x > 0; these are the matrices that define genuine squared distances.

What matrices are not

Multiplying numbers is commutative; multiplying matrices is not. ABAB generally differs from BABA, and that is not a technicality — it says that applying one transformation and then another depends on the order. A rotation followed by a stretch is a different map from the stretch followed by the rotation.

Illustrative vs real

The warp is drawn in 2-D so you can see it, but nothing above is about two dimensions. A transformer layer is a matrix over a few thousand coordinates; the determinant, rank and column-space statements hold verbatim. The picture is a lens, not a restriction.

Check yourself

Eduspheria wiki · Mathematics for AI, Linear algebra

0 / 5 answered

  1. 1What is the determinant of M = [[2, 1], [1, 2]]?
    Numeric answer
  2. 2The columns of a matrix are best described as which of these?
    Multiple choice
  3. 3What is the name of the subspace containing every vector of the form A·x?
    Short answer
  4. 4If det A = 0, then A is not invertible.
    True / false
  5. 5A 4×3 matrix has rank 2. How many dimensions does its null space have?
    Numeric answer

Where next: linear systems — when the equations Ax=bAx = b have a solution, and what to do when they do not.