This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / interpolate / _bsplines / BSpline / insert_knot

function

scipy.interpolate._bsplines:BSpline.insert_knot

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

Signature

def insert_knot(self, x, m = 1)

Summary

Insert a new knot at x of multiplicity m.

Extended Summary

Given the knots and coefficients of a B-spline representation, create a new B-spline with a knot inserted m times at point x.

Parameters

x : float

The position of the new knot

m : int, optional

The number of times to insert the given knot (its multiplicity). Default is 1.

Returns

spl : `BSpline` object

A new BSpline object with the new knot inserted.

Notes

Based on algorithms from [1] and [2].

In case of a periodic spline (self.extrapolate == "periodic") there must be either at least k interior knots t(j) satisfying t(k+1)<t(j)<=x or at least k interior knots t(j) satisfying x<=t(j)<t(n-k).

This routine is functionally equivalent to scipy.interpolate.insert.

Examples

You can insert knots into a B-spline:
import numpy as np
from scipy.interpolate import BSpline, make_interp_spline
x = np.linspace(0, 10, 5)
y = np.sin(x)
spl = make_interp_spline(x, y, k=3)
spl.t
✓
array([ 0.,  0.,  0.,  0.,  5., 10., 10., 10., 10.])
Insert a single knot
spl_1 = spl.insert_knot(3)
spl_1.t
✓
array([ 0.,  0.,  0.,  0.,  3.,  5., 10., 10., 10., 10.])
Insert a multiple knot
spl_2 = spl.insert_knot(8, m=3)
spl_2.t
✓
array([ 0.,  0.,  0.,  0.,  5.,  8.,  8.,  8., 10., 10., 10., 10.])

See also

scipy.interpolate.insert

Aliases

  • scipy.interpolate.BSpline.insert_knot