'Construct a new piecewise polynomial representing the derivative.
Parameters
nu : int, optional
Order of derivative to evaluate. Default is 1, i.e. compute the
first derivative. If negative, the antiderivative is returned.
Returns
pp : PPoly
Piecewise polynomial of order k2 = k - n representing the derivative
of this polynomial.
Notes
Derivatives are evaluated piecewise for each polynomial
segment, even if the polynomial is not differentiable at the
breakpoints. The polynomial intervals are considered half-open,
``[a, b)``, except for the last interval which is closed
``[a, b]``.'

def derivative(self, nu=1):

    if (nu < 0):
        return self.antiderivative((- nu))
    if (nu == 0):
        c2 = self.c.copy()
    else:
        c2 = self.c[:(- nu), :].copy()
    if (c2.shape[0] == 0):
        c2 = np.zeros(((1,) + c2.shape[1:]), dtype=c2.dtype)
    factor = spec.poch(np.arange(c2.shape[0], 0, (-1)), nu)
    c2 *= factor[((slice(None),) + ((None,) * (c2.ndim - 1)))]
    return self.construct_fast(c2, self.x, self.extrapolate, self.axis)
