a11a12x1x2y1y2a21a22r11r12r21r22p11p12p21p2201A @ x2A[:, 0]3np.linalg.det(A)4R @ A5A @ x + b
Cells: A, x, y, R and RA, one number eachCalculator: the running sum of a dot productPlane: what the matrix does to arrows, the grid and the unit squarePython card: the NumPy line for each ideaOne worked example: A = [[2, −1], [1, 1]] times x = (2, 1). Tokens carry each entry × entry into the calculator, and each row's sum into y = (3, 3). On the plane, A moves x to (3, 3), sends e1 and e2 to its columns (2, 1) and (−1, 1), turns the unit square into a parallelogram of area det A = 3, and the quarter turn R carries (3, 3) on to (−3, 3). RA means "apply A first, then R", because (RA)x = R(Ax). Matrix products are associative but not commutative: here RA = [[−1, −1], [2, −1]] while AR = [[−1, −2], [1, −1]].

Matrices and vectors

  1. A matrix is a grid of numbers in rows and columns. A has 2 rows and 2 columns, so it is a 2 × 2 matrix. The entry in row i, column j is written aᵢⱼ: here a₁₁ = 2 and a₁₂ = −1.

Matrix times vector

What A does to the plane

Products at work

Try it in Python (NumPy), in order

;; step 1/11 · A grid of numbers
>>> import numpy as np
>>> A = np.array([[2, -1], [1, 1]])
>>> A.shape                # (rows, columns)
(2, 2)
>>> A[0, 1]                # row 1, column 2 (Python counts from 0)
np.int64(-1)

An m × n matrix has m rows and n columns. It can multiply a vector with n entries and returns a vector with m entries; two matrices P and Q can be multiplied as PQ only when P has as many columns as Q has rows. np.linalg.det works with floating-point numbers (it uses an LU factorisation), so it prints 2.9999999999999996 instead of 3. Round it, or use the exact formula ad − bc for a 2 × 2 matrix.