Review: find the slip (vectors and matrices)
Why this matters
Module 4's slips are mostly about shape. Multiplying cells where rows should meet columns, a weight matrix stored the other way around, row 2 read where column 2 was meant, a math index used as a Python one: each either stops with a shape error or, worse, runs and gives a confident wrong answer. The cure is the habit this review practices: write down the shape of every array, check that the shapes fit before you multiply, and test new code on a case small enough to work by hand. The module's formula sheet gets a shapes column for exactly this reason. With these slips under control, the calculus of Module 5 can lean on matrices without a second thought.
- Spot the common slips of Module 4: shapes that don't fit, * for @, a transposed operand, row and column swapped, and counting from 1
- Find and fix slips in matrix code that runs but gives a wrong answer
- Mix problems from every lesson of the module, and run a short NumPy program in your head, line by line
- Use the module's formula sheet, with a shapes column: each formula, what it says, its shapes and its Python line, and see where Modules 1 to 4 sit in a model
Find the slip
Purpose. Five slips cover most of Module 4's mistakes, and each has a quick check:
*for@.*multiplies matching cells;@pairs rows with columns and adds. Check: a dot product is one number, and A @ x has one entry per row of A.- Shapes that don't fit. (m × n)(n × p) needs the inner sizes to match. Check: write both shapes before multiplying.
- A transposed operand. A weight matrix stored as (outputs, inputs) needs
.TbeforeX @ W. Check: the inner sizes tell you which way around it must be. - Row and column swapped.
A[1]is a row; a column isA[:, 1]. Check: say "row first" aloud. - Counting from 1. The math's a₂₃ is
A[1, 2]. Check: subtract 1 from both numbers.
Below are thirteen worked lines, with a comment saying what each should give. Seven have a slip.