def clgrad(obj, exe, arg, delta=DELTA):
f, x = get_method_and_copy_of_attribute(obj, exe, arg)<EOL>def grad_f(*args, **kwargs):<EOL><INDENT>grad_val = numpy.zeros(x.shape)<EOL>it = numpy.nditer(x, op_flags=['<STR_LIT>'], flags=['<STR_LIT>'])<EOL>for xi in it:<EOL><INDENT>i = it.multi_index<EOL>xi += delta/<NUM_LIT:2><EOL>fp = f(*args, **kwargs)<EOL>xi -= delta<EOL>fm = f(*args, **kwargs)<EOL>xi += delta/<NUM_LIT:2><EOL>grad_val[i] = (fp - fm)/delta<EOL><DEDENT>return grad_val<EOL><DEDENT>return grad_f<EOL>
Returns numerical gradient function of given class method
with respect to a class attribute
Input: obj, general object
       exe (str), name of object method
       arg (str), name of object atribute
       delta(float, optional), finite difference step
Output: gradient function object