Have a go at it. The editor and the docs panel are open, and your code is saved as you type. Running it needs a free account — you’ll come back to exactly what you wrote.
The Jacobian
A gradient is for a function with one output. When a function has several outputs, each one has its own gradient, and stacking them as rows gives the Jacobian:
Row i is the gradient of output i. So a function from to has an (m,n) Jacobian — outputs down, inputs across. Getting that orientation wrong is the classic transpose bug.
Every layer of a neural network is a vector function, and the chain rule for them is Jacobian multiplication: Jtotal=J3J2J1. Backpropagation never forms these matrices — for a layer with a thousand units the Jacobian would have a million entries — but it computes exactly the vector-Jacobian products that this expression implies. Knowing that is what makes dX = dZ @ W.T stop looking arbitrary.
This problem uses
at (x, y) = (1, 0):
J = [[2*1*0, 1^2 ], = [[0, 1],
[5, cos 0]] [5, 1]]Your task:
Implement jacobian_at(x, y) returning the 2×2 Jacobian as a nested list [[df1/dx, df1/dy], [df2/dx, df2/dy]].
Example Tests
At (1, 0) the sine row contributes cos(0) = 1
Input: {"x":1,"y":0}
Expected: [[0,1],[5,1]]
At (2, 1) the top row is [2xy, x^2] = [4, 4]
Input: {"x":2,"y":1}
Expected: [[4,4],[5,0.5403]]
The constant 5 appears in every Jacobian regardless of position
Input: {"x":0,"y":0}
Expected: [[0,0],[5,1]]
import numpy as np
def jacobian_at(x, y):
"""
Jacobian of f(x, y) = [x^2*y, 5x + sin(y)].
Args:
x: first coordinate
y: second coordinate
Returns:
2x2 nested list: rows are outputs, columns are inputs
"""
# YOUR CODE HERE
pass