'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
bp : BPoly
Piecewise polynomial of order k - nu representing the derivative of
this polynomial.'

def derivative(self, nu=1):

    if (nu < 0):
        return self.antiderivative((- nu))
    if (nu > 1):
        bp = self
        for k in range(nu):
            bp = bp.derivative()
        return bp
    if (nu == 0):
        c2 = self.c.copy()
    else:
        rest = ((None,) * (self.c.ndim - 2))
        k = (self.c.shape[0] - 1)
        dx = np.diff(self.x)[((None, slice(None)) + rest)]
        c2 = ((k * np.diff(self.c, axis=0)) / dx)
    if (c2.shape[0] == 0):
        c2 = np.zeros(((1,) + c2.shape[1:]), dtype=c2.dtype)
    return self.construct_fast(c2, self.x, self.extrapolate, self.axis)
