Neural Mastery
← Practice
Jacobian Matrix Evaluationmedium

Jacobian Matrix Evaluation

medium Math for ML 15-20 min

NumPy allowed · plain Python earns 10 bonus points

Linear algebra step 1/4

A vector transforms

Matrix multiplication is the first computation behind every model.
Open lesson →
01vector
02matrix
03transform
04result
[2, −1] × [[1, 2], [−.5, 1]] = [0, −2]

Computed matrix × vector transformation

Compute the Jacobian matrix of a vector-valued nonlinear mapping.

Related Skills

Task

Implement nonlinear_jacobian(W, x, b): for a component-wise quadratic map f_i(x) = sum_j (W_ij * x_j^2) + b_i, compute the m x n Jacobian matrix where J_ij = d f_i / d x_j = 2 * W_ij * x_j. Round each float to 4 decimals.

Function Signature

nonlinear_jacobian(W: list[list[float]], x: list[float], b: list[float]) -> list[list[float]]

Examples

Example 1: 2x2 Nonlinear Map
Input: W = [[1, 2], [3, 4]] x = [1, 1] b = [0, 0]
Output: [[2, 4], [6, 8]]
Explanation: Jacobian at [1.0, 1.0].
Example 2: Zero Coordinate Point
Input: W = [[2, 1], [1, 5]] x = [0, 2] b = [1, -1]
Output: [[0, 4], [0, 20]]
Explanation: First column of Jacobian is zero when x[0]=0.

Constraints

  • W is m x n, x has length n, b has length m.
Python3Saved ✓
def nonlinear_jacobian(W: list[list[float]], x: list[float], b: list[float]) -> list[list[float]]:
"""Compute Jacobian matrix of map f_i(x) = sum_j (W_ij * x_j^2) + b_i.
Return m x n Jacobian matrix where J_ij = 2 * W_ij * x_j rounded to 4 decimals."""
# Your implementation here
pass

Case 1: 2x2 Nonlinear Map
Input: W = [[1, 2], [3, 4]] x = [1, 1] b = [0, 0]
Expected: [[2, 4], [6, 8]]
Case 2: Zero Coordinate Point
Input: W = [[2, 1], [1, 5]] x = [0, 2] b = [1, -1]
Expected: [[0, 4], [0, 20]]