Skip to main content
`Ctrl`+`K`

# scipy.interpolate.BSpline.insert_knot

BSpline.insert_knot(x, m=1)

  Insert a new knot at x of multiplicity m.

  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.

  See also

  `scipy.interpolate.insert`

  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`.

  New in version 1.13.

  References

  [1]

  W. Boehm, “Inserting new knots into b-spline curves.”, Computer Aided Design, 12, p.199-201, 1980. DOI:10.1016/0010-4485(80)90154-2.

  [2]

  P. Dierckx, “Curve and surface fitting with splines, Monographs on Numerical Analysis”, Oxford University Press, 1993.

  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.])