def hessian ( x, the_func, epsilon=1e-8):
"""Numerical approximation to the Hessian
Parameters
------------
x: array-like
The evaluation point
the_func: function
The function. We assume that the function returns the function value and
the associated gradient as the second return element
epsilon: float
The size of the step
"""
N = x.size
h = np.zeros((N,N))
df_0 = the_func ( x )[1]
for i in xrange(N):
xx0 = 1.*x[i]
x[i] = xx0 + epsilon
df_1 = the_func ( x )[1]
h[i,:] = (df_1 - df_0)/epsilon
x[i] = xx0
return h