ml.lab
Python sleeps until you run code
02 Matrices are machines

Checkpoint

Matrices are machines

Twelve questions on matrices as maps, products and shapes, with new numbers and a few classic traps. Work them without the lessons open. You need 80% to pass. The code question needs one line of numpy.

  1. 1

    A linear map sends (1,0)(1, 0) to (3,−1)(3, -1) and (0,1)(0, 1) to (2,5)(2, 5). Which matrix represents it?

  2. 2

    Compute Ax\mathbf{A}\mathbf{x} for A=[10−2311]\mathbf{A} = \begin{bmatrix} 1 & 0 & -2 \\ 3 & 1 & 1 \end{bmatrix} and x=(1,4,−1)\mathbf{x} = (1, 4, -1).

    Ax
  3. 3

    Which of these can be done by multiplying by a 2×22 \times 2 matrix? Select all that apply.

  4. 4

    Find the single matrix that first applies the shear [1201]\begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix} and then stretches horizontally by 3 with [3001]\begin{bmatrix} 3 & 0 \\ 0 & 1 \end{bmatrix}.

  5. 5

    Let A=[2−10134]\mathbf{A} = \begin{bmatrix} 2 & -1 & 0 \\ 1 & 3 & 4 \end{bmatrix} and B=[120−151]\mathbf{B} = \begin{bmatrix} 1 & 2 \\ 0 & -1 \\ 5 & 1 \end{bmatrix}. What is (AB)21(\mathbf{AB})_{21}, the entry in row 2 and column 1?

  6. 6

    In numpy, a has shape (8, 1) and b has shape (3,). What does a + b do?

  7. 7

    An MLP maps 20 input features through two hidden layers of 50 units each to 5 outputs. Every layer is dense with a bias. How many parameters does it have?

  8. 8

    Which expression equals (ABC)⊤(\mathbf{ABC})^\top for matrices whose shapes fit?

  9. 9

    A\mathbf{A} is 100×200100 \times 200, B\mathbf{B} is 200×300200 \times 300 and C\mathbf{C} is 300×10300 \times 10. You compute ABC\mathbf{ABC} with whichever grouping is cheaper. How many multiply-adds does it take?

  10. 10

    Two dense layers with no nonlinearity between them compute (XW1+b1)W2+b2(\mathbf{X}\mathbf{W}_1 + \mathbf{b}_1)\mathbf{W}_2 + \mathbf{b}_2 in the row-batch convention. Which single layer XW+b\mathbf{X}\mathbf{W} + \mathbf{b} gives the same outputs?

  11. 11

    Write the matrix that rotates the plane a quarter turn clockwise.

  12. 12
    Code it

    A colleague stores a layer's weights in the math convention: W has shape (d_out, d_in), so one input column becomes Wx+b\mathbf{W}\mathbf{x} + \mathbf{b}. Your data is a batch X of shape (batch, d_in), one example per row. Write layer(X, W, b) so that it returns every example's output as a row, shape (batch, d_out), without a Python loop.

    ⌘↵ runsPython sleeps until you run code
12 still unanswered. Unanswered questions count as wrong.