Skip to content
DeepForgeby svx
All problems
HardCalculusca-329

General Quadratic Form Hessian

Problem

For f(x) = x^T A x with a general square matrix A, the Hessian is the symmetric part A + A^T, independent of x.

Given A as nested rows, return the Hessian.

Hint

Only the symmetric part of A survives in the second derivative.

Test cases

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

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