Start studying
Module 2 · Maths for Data Module contents
Module 2  ·  Card 9 / 13intermediate

Matrix Multiplication

Matrix multiplication combines two matrices by calculating the dot product of each row from the first with each column from the second.

It requires the number of columns in the first matrix to match the number of rows in the second matrix.

Multiplying an m-by-k matrix by a k-by-n matrix produces a new matrix with dimensions m-by-n.

Unlike ordinary multiplication of numbers, matrix multiplication is not commutative, meaning A times B does not equal B times A.

In data science, it is used to apply transformations, rotate coordinates, project high-dimensional data, and compute linear predictions.

Learn in depth ↓
Module 02 · Maths for Data · 13 concepts
In depth  /  15 lines

Matrix Multiplication, in more detail

Matrix multiplication is the computational engine of linear models, graphics transformations, and data projections.

It is distinct from element-wise multiplication, which simply multiplies matching positions in arrays of identical shape.

The standard matrix product requires an inner dimension match: matrix A must have as many columns as matrix B has rows.

If A has shape m by k and B has shape k by n, their product C will have shape m by n.

The entry in row i and column j of product C is computed as the dot product between row i of A and column j of B.

This involves taking pairs of numbers, multiplying them together, and accumulating their sum into a single output cell.

Because row vectors multiply column vectors, changing the order of multiplication changes the entire operation.

For most matrices, A times B does not equal B times A, and in many cases B times A is not even dimensionally valid.

Matrix multiplication is associative, meaning A times the product of B and C equals the product of A and B times C.

It is also distributive over matrix addition: A times the sum of B and C equals A times B plus A times C.

In analytical pipelines, multiplying a feature matrix by a vector of weights calculates predicted scores for all rows at once.

A common beginner error is trying to multiply two matrices simply because they share identical dimensions.

Two rectangular matrices of shape three-by-four cannot be multiplied together because the inner dimensions four and three do not match.

Modern computing hardware uses specialised parallel processors to execute massive matrix multiplications at high speed.

Understanding matrix multiplication allows you to express thousands of individual calculations in a single compact equation.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
Matrix A has shape 10 by 3, and matrix B has shape 3 by 5. Can they be multiplied as A times B, and what is the output shape?
Maths for Data

13 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close