Linear Algebra
4.210 min read

Defining Matrix-Matrix Multiplication

The matrix product C=ABC = AB is defined so that CC represents the composition of the linear maps represented by AA and BB. Specifically: Cv=A(Bv)C\mathbf{v} = A(B\mathbf{v}) for all v\mathbf{v}.

This definition immediately gives us the size rule: if AA is m×nm \times n and BB is n×pn \times p, then C=ABC = AB is m×pm \times p. The inner dimension nn is "consumed" — it represents the intermediate space where BB outputs and AA inputs.

The product is only defined when the number of columns of AA equals the number of rows of BB. This is not a convention — it's forced by the composition definition.

Formal View

Definition 4.2 — Matrix Product
For ARm×nA \in \mathbb{R}^{m \times n} and BRn×pB \in \mathbb{R}^{n \times p}, the matrix product C=ABRm×pC = AB \in \mathbb{R}^{m \times p} is the unique matrix satisfying Cv=A(Bv)C\mathbf{v} = A(B\mathbf{v}) for all vRp\mathbf{v} \in \mathbb{R}^p.

Why This Matters

Understanding that AB = "do B first, then A" is the key to using matrix multiplication correctly.

  • In deep learning, ABAB where BB encodes features and AA classifies: compose the two operations
  • 3D transformation matrices: RotateScale\text{Rotate} \cdot \text{Scale} applies scale first, then rotation

Quiz

Question 1

Can we compute ABAB if AA is 3×43 \times 4 and BB is 3×23 \times 2?

Common Mistakes

  • Checking the wrong dimensions — columns of AA must match rows of BB, not rows of AA with rows of BB.