Skip to content
DeepForgeby svx
All problems
EasyCalculusca-316

Frobenius Norm Squared Gradient

Problem

For the squared Frobenius norm f(A) = sum_ij A_ij^2, the gradient with respect to A is 2A elementwise.

Given A as a nested list of rows, return the gradient in the same shape.

Hint

Each entry of the gradient only depends on the matching entry of A.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: [[2,4],[6,8]]
case 2
in: [[[0,-1],[2,0]]]
expected: [[0,-2],[4,0]]
case 3
in: [[[1.5]]]
expected: [[3]]
Starter codePython
def frobenius_norm_squared_gradient(a):
    # Your code here
    pass

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