ml.lab
Python sleeps until you run code

Module 2 · 4 lessons · about 260 minutes

Matrices are machines

Matrices as linear transformations, matrix multiplication as composition, and the shapes and batches that every neural network layer is made of.

Lessons
0/4
Exercises
0/20
Code
0/4
Checkpoint
Not taken

Already comfortable with this? Take the checkpoint cold. If you pass, move on and come back only for what you missed.

  1. 1Matrices as transformationsA matrix is a function you can write down. Its columns record where the basis vectors land, and that is enough to know where every vector goes. Read row by row, the same numbers are a layer of neurons.85 min
  2. 2Matrix multiplicationDoing one transformation after another is again a transformation, and its matrix is the product. The row-times-column rule falls out of that, along with three ways to read a product and a way to count its cost.75 min
  3. 3Shapes, transposes and batchesReading shapes is the skill that prevents most bugs. This lesson builds that habit, introduces the transpose, turns the column vectors of math into the row batches of code, and shows how numpy stretches one bias across a whole batch.55 min
  4. 4Layers and parameter countsA dense layer is a matrix product plus a bias, and a network is a stack of them with nonlinearities in between. This lesson shows why the nonlinearities are needed, then counts parameters and multiply-adds from a small network up to a 7B model.45 min
  5. Checkpoint12 questions. Pass with 80% to finish the module.

Practice sets for this module

Fresh problems every time. Use them until the mechanics feel automatic.

Practice setMatrix-vector reps
3 correct in a row completes the set. A miss starts the count again.

Compute Ax\mathbf{A}\mathbf{x} for A=[−21−3−11−3]\mathbf{A} = \begin{bmatrix}-2 & 1 & -3 \\ -1 & 1 & -3\end{bmatrix} and x=[21−2]\mathbf{x} = \begin{bmatrix}2 \\ 1 \\ -2\end{bmatrix}.

Ax

One entry per box, top to bottom. 0.25, -2, 3/4 and sqrt(2) all work. Enter moves to the next empty box and checks once all are filled.

Practice setMatrix product reps
3 correct in a row completes the set. A miss starts the count again.

Compute AB\mathbf{A}\mathbf{B} for A=[00−2−220]\mathbf{A} = \begin{bmatrix}0 & 0 \\ -2 & -2 \\ 2 & 0\end{bmatrix} and B=[13−1−213]\mathbf{B} = \begin{bmatrix}1 & 3 & -1 \\ -2 & 1 & 3\end{bmatrix}.

AB

One entry per box, row by row (Tab moves along a row). 0.25, -2, 3/4 and sqrt(2) all work. Enter moves to the next empty box and checks once all are filled.

Practice setShape reps
3 correct in a row completes the set. A miss starts the count again.

In numpy, A has shape (10, 12) and b has shape (10,). What is the shape of A + b?

Next moduleDeterminants, inverses and rank