Linear algebra

Matrix multiplication

Matrix multiplication composes linear maps. Each result entry is a row-column dot product, and the inner dimensions must match.

Ask the Linear algebra assistant 1 min read · Updated September 9, 2026

Definition

Matrix multiplication composes linear maps. Each result entry is a row-column dot product, and the inner dimensions must match.

Intuition

Applying B and then A corresponds to AB, so the order is significant.

Worked example

If A is 2 by 3 and B is 3 by 4, AB is 2 by 4. BA is not defined for those shapes.

The math

For A∈Rm×nA\in\mathbb{R}^{m\times n} and B∈Rn×pB\in\mathbb{R}^{n\times p}, (AB)ij=∑kAikBkj(AB)_{ij}=\sum_k A_{ik}B_{kj}.

In machine learning

Check tensor shapes before optimizing a neural layer; transposition mistakes can produce plausible but incorrect values.

Sources

More in Linear algebra

Assembled from the ReLU.chat curated knowledge base. These explanations are concise on purpose; check the sources for anything important.