def _approx_fprime_helper(xk, f, epsilon, args=(), f0=None):
 if (f0 is None):
  f0 = f(*((xk,) + args))
 grad = numpy.zeros((len(xk),), float)
 ei = numpy.zeros((len(xk),), float)
 for k in range(len(xk)):
  ei[k] = 1.0
  d = (epsilon * ei)
  grad[k] = ((f(*(((xk + d),) + args)) - f0) / d[k])
  ei[k] = 0.0
 return grad

def _approx_fprime_helper ( xk , f , epsilon , args = ( ) , f0 = None ) : if ( f0 is None ) : f0 = f ( * ( ( xk , ) + args ) ) grad = numpy . zeros ( ( len ( xk ) , ) , float ) ei = numpy . zeros ( ( len ( xk ) , ) , float ) for k in range ( len ( xk ) ) : ei [ k ] = 1.0 d = ( epsilon * ei ) grad [ k ] = ( ( f ( * ( ( ( xk + d ) , ) + args ) ) - f0 ) / d [ k ] ) ei [ k ] = 0.0 return grad
see approx_fprime .