def _grad(self, funct, params=None, dl=<NUM_LIT>, rts=False, nout=<NUM_LIT:1>, out=None,<EOL>**kwargs):
if params is None:<EOL><INDENT>params = self.param_all()<EOL><DEDENT>ps = util.listify(params)<EOL>f0 = funct(**kwargs)<EOL>calc_shape = (<EOL>lambda ar: (len(ps),) + (ar.shape if isinstance(<EOL>ar, np.ndarray) else (<NUM_LIT:1>,)))<EOL>if out is not None:<EOL><INDENT>grad = out  <EOL><DEDENT>elif nout == <NUM_LIT:1>:<EOL><INDENT>shape = calc_shape(f0)<EOL>grad = np.zeros(shape)  <EOL><DEDENT>else:<EOL><INDENT>shape = [calc_shape(f0[i]) for i in range(nout)]<EOL>grad = [np.zeros(shp) for shp in shape]<EOL><DEDENT>for i, p in enumerate(ps):<EOL><INDENT>if nout == <NUM_LIT:1>:<EOL><INDENT>grad[i] = self._grad_one_param(funct, p, dl=dl, rts=rts,<EOL>nout=nout, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>stuff = self._grad_one_param(funct, p, dl=dl, rts=rts,<EOL>nout=nout, **kwargs)<EOL>for a in range(nout): grad[a][i] = stuff[a]<EOL><DEDENT><DEDENT>return grad<EOL>
Gradient of `func` wrt a set of parameters params. (see _graddoc)