Skip to content
DeepForgeby svx
All problems
MediumCalculusca-294

Chain Rule Through Two Linear Maps

Problem

For the composition y = W2 @ (W1 @ x) with constant matrices, the Jacobian with respect to x is the product W2 @ W1.

Given W1 as a list of rows (m x n) and W2 as a list of rows (k x m), return the k x n Jacobian as a nested list.

Hint

Compose the linear maps by multiplying the matrices in order.

Test cases

case 1
in: [[[1,2],[3,4]],[[1,0]]]
expected: [[1,2]]
case 2
in: [[[1,0],[0,1]],[[2,3],[4,5]]]
expected: [[2,3],[4,5]]
case 3
in: [[[2]],[[3]]]
expected: [[6]]
Starter codePython
def chain_rule_linear_jacobian(w1, w2):
    # Your code here
    pass

3 test cases · run your code against them in the editor