I'm trying to define a simple function ddf() that outputs the Hessian matrix of a particular mathematical function, given a 2D vector, x as the input :
import numpy as np
def ddf(x):
dd11 = 2*x[1]+8
dd12 = 2*x[0]-8*x[1]-8
dd21 = 2*x[0]-8*x[1]-8
dd22 = -8*x[0]+2
return np.array([[dd11, dd12], [dd21, dd22]])
x0 = np.zeros((2,1))
G = ddf(x0)
print(G)
I expect the output to be a 2x2 square array/matrix, however it yields what appears to be a 4x1 column instead. Stranger still, using
G.shape
yields (2L, 2L, 1L), not (2L,2L) as expected. My objective is to obtain G in 2x2 form. Can anyone assist? Thanks