derivative#
- BSpline.derivative(nu=1)[source]#
Return a B-spline representing the derivative.
- Parameters:
- nuint, optional
Derivative order. Default is 1.
- Returns:
- b
BSplineobject A new instance representing the derivative.
- b
See also
Notes
The coefficient array of the returned instance will be padded with
b.k + 1trailing zeros, so thatlen(b.c) == len(b.t). The trailing coefficients never enter evaluations, only the firstlen(b.t) - b.k - 1coefficients are used.Examples
>>> import numpy as np >>> from scipy.interpolate import BSpline, make_interp_spline >>> x = np.arange(11) >>> y = x**4 + np.sin(x) >>> spl = make_interp_spline(x, y, k=3)
A spline of degree
kis built from polynomial pieces of degreek, joined at the knotst. The number of knots, the number of coefficients, and the degree are related bylen(t) - len(c) == k + 1. Padded coefficients instead satisfylen(c) == len(t):>>> len(spl.t), len(spl.c), spl.k # knots, coefficients, degree of spl (15, 11, 3) >>> b = spl.derivative() # b is a quadratic spline >>> len(b.t), len(b.c), b.k # knots, coefficients, degree of b (13, 13, 2) >>> b.c[len(b.t) - b.k - 1:] # zero padding, unused in evaluations array([0., 0., 0.])
Slice off the padding to get exactly
len(b.t) - b.k - 1coefficients:>>> c = b.c[:len(b.t) - b.k - 1] >>> len(c) 10
The trimmed coefficients define the same spline, since the padding never enters evaluations. Evaluating the spline before (
b) and after (BSpline(b.t, c, b.k)) trimming on a grid of points spanning the data range gives the same values:>>> xx = np.linspace(0, 10, 51) >>> np.allclose(BSpline(b.t, c, b.k)(xx), b(xx)) True