def derivative(self, nu=<NUM_LIT:1>):
if nu < <NUM_LIT:0>:<EOL><INDENT>raise NotImplementedError('<STR_LIT>')<EOL><DEDENT>if nu > <NUM_LIT:1>:<EOL><INDENT>bp = self<EOL>for k in range(nu):<EOL><INDENT>bp = bp.derivative()<EOL><DEDENT>return bp<EOL><DEDENT>if nu == <NUM_LIT:0>:<EOL><INDENT>c2 = self.c.copy()<EOL><DEDENT>else:<EOL><INDENT>rest = (None,)*(self.c.ndim-<NUM_LIT:2>)<EOL>k = self.c.shape[<NUM_LIT:0>] - <NUM_LIT:1><EOL>dx = np.diff(self.x)[(None, slice(None))+rest]<EOL>c2 = k * np.diff(self.c, axis=<NUM_LIT:0>) / dx<EOL><DEDENT>if c2.shape[<NUM_LIT:0>] == <NUM_LIT:0>:<EOL><INDENT>c2 = np.zeros((<NUM_LIT:1>,) + c2.shape[<NUM_LIT:1>:], dtype=c2.dtype)<EOL><DEDENT>return self.construct_fast(c2, self.x, self.extrapolate)<EOL>
Construct a new piecewise polynomial representing the derivative.

Parameters
----------
nu : int, optional
    Order of derivative to evaluate. (Default: 1)
    If negative, the antiderivative is returned.

Returns
-------
bp : BPoly
    Piecewise polynomial of order k2 = k - nu representing the derivative
    of this polynomial.