This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / interpolate / _bsplines / BSpline / basis_element

classmethod

scipy.interpolate._bsplines:BSpline.basis_element

source: build-install/usr/lib/python3.14/site-packages/scipy/interpolate/_bsplines.py:960

Summary

Return a B-spline basis element B(x | t[0], ..., t[k+1]).

Parameters

t : ndarray, shape (k+2,)

internal knots

extrapolate : bool or 'periodic', optional

whether to extrapolate beyond the base interval, t[0] .. t[k+1], or to return nans. If 'periodic', periodic extrapolation is used. Default is True.

Returns

basis_element : callable

A callable representing a B-spline basis element for the knot vector t.

Notes

The degree of the B-spline, k, is inferred from the length of t as len(t)-2. The knot vector is constructed by appending and prepending k+1 elements to internal knots t.

Examples

Construct a cubic B-spline:
import numpy as np
from scipy.interpolate import BSpline
b = BSpline.basis_element([0, 1, 2, 3, 4])
k = b.k
✓
b.t[k:-k]
✗
array([0., 1., 2., 3., 4.])
k
✓
3
Construct a quadratic B-spline on ``[0, 1, 1, 2]``, and compare to its explicit form:
t = [0, 1, 1, 2]
b = BSpline.basis_element(t)
def f(x):
    return np.where(x < 1, x*x, (2. - x)**2)
✓
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = np.linspace(0, 2, 51)
✓
ax.plot(x, b(x), 'g', lw=3)
ax.plot(x, f(x), 'r', lw=8, alpha=0.4)
✗
[<matplotlib.lines.Line2D object at 0x7f3f433be120>]
ax.grid(True)
plt.show()
✓
fig-6f415aaffcd7d1f0.png

Aliases

  • scipy.interpolate.BSpline.basis_element