1C = [[0, 0], [0, 0]]2for i in range(2):3 for j in range(2):4 for k in range(3):5 C[i][j] += A[i][k]*B[k][j]6np.array(A) @ B0b₁₁7b₁₂8b₂₁9b₂₂10b₃₁11b₃₂12a₁₁1a₁₂2a₁₃3a₂₁4a₂₂5a₂₃6c₁₁c₁₂c₂₁c₂₂
Matrix cells: the entry's name on top, its number belowTrays: the row and column being paired, and the pair being multipliedCalculator: the running sum of the current dot productPython card: the triple loop, and NumPy's @ operatorA (2 × 3) times B (3 × 2) gives C (2 × 2). The matrices stand in Falk's scheme: B behind C and A to its left, so each entry of C sits where a row of A meets a column of B. Trays mark the row and the column being paired and the pair being multiplied; tokens carry each product into the calculator, and the running sum flies into its cell: 58, 64, 139, 154. A vector is a matrix with one column. A 2 × 3 matrix times a 3-entry vector gives a 2-entry vector: A · (7, 9, 11) = (58, 139).

Shapes

  1. A has 2 rows and 3 columns: it is 2 × 3. B is 3 × 2. You can multiply A by B only when A's columns match B's rows: 3 = 3. The result C takes A's rows and B's columns: 2 × 2.

Dot products

Reading the rule

In code

Try it in the Python prompt

;; step 1/10 · Check the shapes first
>>> A = [[1, 2, 3], [4, 5, 6]]
>>> B = [[7, 8], [9, 10], [11, 12]]
>>> len(A), len(A[0]), len(B), len(B[0])
(2, 3, 3, 2)

Maths numbers rows and columns from 1, so c₁₁ is row 1, column 1. Python lists count from 0, so the same entry is C[0][0]. Matrix multiplication is associative, (AB)C = A(BC), and distributes over addition, A(B + C) = AB + AC, but it is not commutative: AB and BA usually differ.