scipy.interpolate.
插入#
- scipy.interpolate.insert(x, tck, m=1, per=0)[源代码][源代码]#
在B样条中插入节点。
给定B样条表示的节点和系数,在点`x`处插入`m`次节点,创建一个新的B样条。这是对FITPACK的FORTRAN例程insert的封装。
- 参数:
- 返回:
- BSpline 实例或一个元组
一个新的 B 样条,具有节点 t、系数 c 和度数 k。
t(k+1) <= x <= t(n-k),其中 k 是样条的度数。如果是周期性样条(per != 0),则必须至少有 k 个内部节点 t(j) 满足t(k+1)<t(j)<=x或至少有 k 个内部节点 t(j) 满足x<=t(j)<t(n-k)。如果输入参数 tck 是元组,则返回一个元组,否则构造并返回一个 BSpline 对象。
注释
不建议直接操作 tck-tuples。在新代码中,建议使用
BSpline对象,特别是BSpline.insert_knot方法。参考文献
[1]W. Boehm, “Inserting new knots into b-spline curves.”, Computer Aided Design, 12, p.199-201, 1980.
[2]P. Dierckx, “Curve and surface fitting with splines, Monographs on Numerical Analysis”, Oxford University Press, 1993.
示例
你可以在B样条中插入节点。
>>> from scipy.interpolate import splrep, insert >>> import numpy as np >>> x = np.linspace(0, 10, 5) >>> y = np.sin(x) >>> tck = splrep(x, y) >>> tck[0] array([ 0., 0., 0., 0., 5., 10., 10., 10., 10.])
插入一个结:
>>> tck_inserted = insert(3, tck) >>> tck_inserted[0] array([ 0., 0., 0., 0., 3., 5., 10., 10., 10., 10.])
插入了一些结:
>>> tck_inserted2 = insert(8, tck, m=3) >>> tck_inserted2[0] array([ 0., 0., 0., 0., 5., 8., 8., 8., 10., 10., 10., 10.])