Index Ai Academy
Foundation · Foundation mathVectors and matrices

Review: find the slip (vectors and matrices)

About 36 minLooking ahead: some prerequisites aren't done yet

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
Quick check
Have a guess before you start. A learner computes the dot product of (1, 2, 2) and (2, 1, 2) and gets [2 2 4]. What went wrong?

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 .T before X @ W. Check: the inner sizes tell you which way around it must be.
  • Row and column swapped. A[1] is a row; a column is A[:, 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.