scipy.interpolate.BSpline.
insert_knot#
- BSpline.insert_knot(x, m=1)[source]#
在 x 處插入一個新的節點,其重數為 m。
給定 B 樣條表示法的節點和係數,建立一個新的 B 樣條,在點 x 處插入 m 次節點。
- 參數:
- xfloat
新節點的位置
- mint, optional
要插入給定節點的次數(其重數)。預設值為 1。
- 回傳值:
- splBSpline 物件
一個插入新節點的新 BSpline 物件。
註解
在週期性樣條 (
self.extrapolate == "periodic"
) 的情況下,必須至少有 k 個內部節點 t(j) 滿足t(k+1)<t(j)<=x
或至少有 k 個內部節點 t(j) 滿足x<=t(j)<t(n-k)
。此常式在功能上等同於
scipy.interpolate.insert
。在 1.13 版本中新增。
參考文獻
[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.
範例
您可以將節點插入 B 樣條
>>> 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.])
插入單一節點
>>> spl_1 = spl.insert_knot(3) >>> spl_1.t array([ 0., 0., 0., 0., 3., 5., 10., 10., 10., 10.])
插入多重節點
>>> spl_2 = spl.insert_knot(8, m=3) >>> spl_2.t array([ 0., 0., 0., 0., 5., 8., 8., 8., 10., 10., 10., 10.])