def approx_jacobian(x, func, epsilon, *args):
 x0 = asfarray(x)
 f0 = atleast_1d(func(*((x0,) + args)))
 jac = zeros([len(x0), len(f0)])
 dx = zeros(len(x0))
 for i in range(len(x0)):
  dx[i] = epsilon
  jac[i] = ((func(*(((x0 + dx),) + args)) - f0) / epsilon)
  dx[i] = 0.0
 return jac.transpose()

def approx_jacobian ( x , func , epsilon , * args ) : x0 = asfarray ( x ) f0 = atleast_1d ( func ( * ( ( x0 , ) + args ) ) ) jac = zeros ( [ len ( x0 ) , len ( f0 ) ] ) dx = zeros ( len ( x0 ) ) for i in range ( len ( x0 ) ) : dx [ i ] = epsilon jac [ i ] = ( ( func ( * ( ( ( x0 + dx ) , ) + args ) ) - f0 ) / epsilon ) dx [ i ] = 0.0 return jac . transpose ( )
approximate the jacobian matrix of a callable function .