scipy.interpolate.BSpline.
insert_knot#
- BSpline.insert_knot(x, m=1)[source]#
在 x 处插入一个重数为 m 的新节点。
给定 B 样条表示的节点和系数,创建一个新的 B 样条,在点 x 处插入 m 次节点。
注释
对于周期性样条 (
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.])