def approx_hess_cs(x, f, epsilon=None, args=(), kwargs={}):
 n = len(x)
 h = _get_epsilon(x, 3, epsilon, n)
 ee = np.diag(h)
 hess = np.outer(h, h)
 n = len(x)
 for i in range(n):
  for j in range(i, n):
   hess[(i, j)] = (((f(*((((x + (1j * ee[i, :])) + ee[j, :]),) + args), **kwargs) - f(*((((x + (1j * ee[i, :])) - ee[j, :]),) + args), **kwargs)).imag / 2.0) / hess[(i, j)])
   hess[(j, i)] = hess[(i, j)]
 return hess

def approx_hess_cs ( x , f , epsilon = None , args = ( ) , kwargs = { } ) : n = len ( x ) h = _get_epsilon ( x , 3 , epsilon , n ) ee = np . diag ( h ) hess = np . outer ( h , h ) n = len ( x ) for i in range ( n ) : for j in range ( i , n ) : hess [ ( i , j ) ] = ( ( ( f ( * ( ( ( ( x + ( 1j * ee [ i , : ] ) ) + ee [ j , : ] ) , ) + args ) , ** kwargs ) - f ( * ( ( ( ( x + ( 1j * ee [ i , : ] ) ) - ee [ j , : ] ) , ) + args ) , ** kwargs ) ) . imag / 2.0 ) / hess [ ( i , j ) ] ) hess [ ( j , i ) ] = hess [ ( i , j ) ] return hess
calculate hessian with complex-step derivative approximation parameters x : array_like value at which function derivative is evaluated f : function function of one array f(x) epsilon : float stepsize .