environment · importance: high
How to Multiply Matrices
Matrix multiplication is the core operation of linear algebra and every neural network. The rule is simple once memorised: inner dimensions match, outer dimensions give the result shape, and each element is a row-times-column dot product. Practice by hand at 2×2 and 3×3 until the pattern is automatic.
When the method applies
- • Dimensions do not seem to match
- • Element (i,j) of the product is unclear
- • Mixed up rows and columns
- • Cannot multiply non-square matrices
Common mistakes
- • Forgot the inner-dimension rule (m×n times n×p = m×p)
- • Reading rows of B instead of columns
- • Trying to multiply element-wise (that is Hadamard product)
Step-by-step method
- • Check dimensions: A is m×n, B is n×p → result is m×p (inner n must match)
- • Element (i,j) of AB = dot product of row i of A with column j of B
- • (AB)ᵢⱼ = Σₖ Aᵢₖ · Bₖⱼ
- • For 2×2: [[a,b],[c,d]] · [[e,f],[g,h]] = [[ae+bg, af+bh], [ce+dg, cf+dh]]
- • Use NumPy: A @ B (Python operator) or np.matmul(A, B)
Advertisement slot
Build long-term fluency
- • Drill 10 small matrix products by hand weekly
- • Always state dimensions before multiplying
- • Remember: matrix multiplication is NOT commutative — AB ≠ BA
Edge cases & deeper reading
If you need eigenvalues, determinants, or matrix inverses, see linear algebra. For ML/CS use, numpy and PyTorch do all this for you — but the dimension intuition is yours to build.
Shop Recommended Practice
Editor-vetted picks for recommended practice — textbooks, workbooks, and interactive courses.
Affiliate links — we may earn a small commission at no cost to you. Disclosure.