Textbook
If $A\in\mathbb R^{m\times n}$ and $B\in\mathbb R^{n\times p}$, their product $AB\in\mathbb R^{m\times p}$ is defined by $(AB)_{ij}:=\sum_{k=1}^n A_{ik}B_{kj}$. The inner dimensions $n$ must agree. Each output entry is the sum of corresponding products from row $i$ and column $j$.
Multiplying a matrix by a column vector is the case $p=1$. Unlike elementwise multiplication, an output usually combines several input numbers. The factor order matters: the reverse product may have another shape, another value, or no definition.
In the formula, $i$ and $j$ locate the output entry, while $k$ runs through the terms within that one entry. Its range fits both the chosen row and column because the inner dimensions agree. At $n=1$, the sum has one product but follows the same rule. Zero entries give zero contributions without removing positions or dimension requirements.
Definitions and further reading: Mathematics for Machine Learning.
In plain language
Matrix multiplication resembles a collection of recipes: a row specifies coefficients and a column supplies matching quantities. Pairwise products are added into one output, and the next row defines another recipe. Matching inner dimensions checks the number of positions, while semantic agreement of the data requires a separate check. A kitchen can calculate an order with flour and salt exchanged without philosophical objections; matching package positions is not enough.
Example
In the original illustrative example, the matrix with rows $(1,2)$ and $(0,1)$ is multiplied by column $(3,4)^{\mathsf T}$. Shape checking precedes computing the two outputs.
Matrix Multiplication: A Row Meets a Column
Compatible shapes
The inner dimensions are both two; the result is a two-entry column.
Step 1 of 3: Compatible shapes
Read all steps
Compatible shapes
The inner dimensions are both two; the result is a two-entry column.
- A₁
- 1current2current
- A₂
- 0current1current
- x
- 3current4current
First output
The first row gives 1 × 3 + 2 × 4 = 11.
- A₁
- 1 × 3current2 × 4current
- y₁
- 11current
Second output
The second row gives 0 × 3 + 1 × 4 = 4.
- A₂
- 0 × 3current1 × 4current
- y
- 11current4current
The first output 11 contains a contribution of 3 from the first input and 8 from the second. In the second output, the first input is multiplied by zero, leaving only 4. These two outputs remain separate; 11 and 4 are not added together. A shape check helps too: a two-row matrix times a compatible column gives a column with two outputs, rather than one number or a four-entry table.
Related concepts: Finite sums, Elementwise products.