Machine learning

Stage 2 · Lesson 2 of 9

Matrix multiplication and shapes

The maths you need

You can multiply a matrix of (m, n) by one of shape (n, p), and the answer has shape (m, p). The two inner numbers must match. Each cell of the answer is the of one row from the first matrix and one column from the second.

This is how a whole batch of predictions is made at once: X of shape (1000, 3) times of shape (3, 1) gives 1,000 predictions, shape (1000, 1). Every neural network layer later on is a matrix multiplication plus a bias. Reading shapes here is what lets you fix errors like 'mat1 and mat2 shapes cannot be multiplied'. Also learn the , which swaps rows and columns.

Common trapthinking order does not matter: A @ B and B @ A usually differ, and often one of them is not even allowed.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Keep handy

Also worth your time

Mark this stage as not done?