def hessian(f, delta=DELTA):
def hessian_f(*args, **kwargs):<EOL><INDENT>if len(args) == <NUM_LIT:1>:<EOL><INDENT>x, = args<EOL>hessianf_x = (<EOL>f(x+delta) + f(x-delta) - <NUM_LIT:2>*f(x)<EOL>)/delta**<NUM_LIT:2><EOL>return hessianf_x<EOL><DEDENT>elif len(args) == <NUM_LIT:2>:<EOL><INDENT>x, y = args<EOL>if type(x) in [float, int] and type(y) in [float, int]:<EOL><INDENT>hess_xx = (<EOL>f(x + delta, y) + f(x - delta, y) - <NUM_LIT:2>*f(x, y)<EOL>)/delta**<NUM_LIT:2><EOL>hess_yy = (<EOL>f(x, y + delta) + f(x, y - delta) - <NUM_LIT:2>*f(x, y)<EOL>)/delta**<NUM_LIT:2><EOL>hess_xy = (<EOL>+ f(x+delta/<NUM_LIT:2>, y+delta/<NUM_LIT:2>)<EOL>+ f(x-delta/<NUM_LIT:2>, y-delta/<NUM_LIT:2>)<EOL>- f(x+delta/<NUM_LIT:2>, y-delta/<NUM_LIT:2>)<EOL>- f(x-delta/<NUM_LIT:2>, y+delta/<NUM_LIT:2>)<EOL>)/delta**<NUM_LIT:2><EOL>return hess_xx, hess_xy, hess_yy<EOL><DEDENT><DEDENT><DEDENT>return hessian_f<EOL>
Returns numerical hessian function of given input function
Input: f, scalar function of one or two variables
       delta(optional), finite difference step
Output: hessian function object