Repository: scipy/scipy
File: scipy/interpolate/_ndbspline.py (Python)

Code before:
                new_t = db.t

            new_c_list.append(db.c)

        new_c = np.stack(new_c_list, axis=1).reshape(
            (len(new_c_list[0]),) + trailing_shape)
        new_c = np.moveaxis(new_c, 0, axis)

        return new_c, new_t

    def derivative(self, nu=1):
        """
        Construct a new NdBSpline representing the derivative.

        Parameters
        ----------
        nu : int or array_like of shape (ndim,)
            Order(s) of the derivative to compute along each dimension.
            A single integer means the same order for all dimensions.

        Returns
        -------
        NdBSpline
            A new NdBSpline representing the derivative.
        """
        nu_arr = np.atleast_1d(nu)
        ndim = len(self.t)

        if nu_arr.ndim > 1 or (nu_arr.shape[0] != 1 and nu_arr.shape[0] != ndim):
            raise ValueError(f"Invalid derivative orders {nu = } for ndim = {ndim}")

        if nu_arr.shape[0] == 1:
            nu_arr = np.repeat(nu_arr, ndim)

        if any(n < 0 for n in nu_arr):
            raise ValueError("Derivative orders must be non-negative")

        t_new = list(self.t)
        k_new = list(self.k)
        c_new = self.c.copy()

        for axis, n in enumerate(nu_arr):
            if n == 0:
                continue

            c_new, t_new[axis] = self._bspline_derivative_along_axis(
                c_new, t_new[axis], k_new[axis], axis, nu=n
            )
            k_new[axis] = max(k_new[axis] - n, 0)

        return NdBSpline(tuple(t_new), c_new,

Review comment (suggestion):

These two should be consistent:

```
(Pdb) bspl2(xi, nu=42)
*** ValueError: invalid number of derivative orders nu = array(42) for ndim = 2.
(Pdb) bspl2.derivative(42).k
(np.int64(0), np.int64(0))
```

Here `bspl2` is from https://github.com/scipy/scipy/issues/23510 (which is separate). 

Code after:
                new_t = db.t

            new_c_list.append(db.c)

        new_c = np.stack(new_c_list, axis=1).reshape(
            (len(new_c_list[0]),) + trailing_shape)
        new_c = np.moveaxis(new_c, 0, axis)

        return new_c, new_t

    def derivative(self, nu=1):
        """
        Construct a new NdBSpline representing the derivative.

        Parameters
        ----------
        nu : array_like of shape (ndim,)
            Order(s) of the derivative to compute along each dimension.

        Returns
        -------
        NdBSpline
            A new NdBSpline representing the derivative.
        """
        nu_arr = np.asarray(nu, dtype=np.int64)
        ndim = len(self.t)

        if nu_arr.ndim != 1 or nu_arr.shape[0] != ndim:
            raise ValueError(
                f"invalid number of derivative orders {nu = } for "
                f"ndim = {len(self.t)}.")

        if any(n < 0 for n in nu_arr):
            raise ValueError(f"derivatives must be positive, got {nu = }")

        t_new = list(self.t)
        k_new = list(self.k)
        c_new = self.c.copy()

        for axis, n in enumerate(nu_arr):
            if n == 0:
                continue

            c_new, t_new[axis] = self._bspline_derivative_along_axis(
                c_new, t_new[axis], k_new[axis], axis, nu=n
            )
            k_new[axis] = max(k_new[axis] - n, 0)

        return NdBSpline(tuple(t_new), c_new,
                         tuple(k_new), extrapolate=self.extrapolate)