scipy.interpolate.

插入#

scipy.interpolate.insert(x, tck, m=1, per=0)[源代码][源代码]#

在B样条中插入节点。

给定B样条表示的节点和系数,在点`x`处插入`m`次节点,创建一个新的B样条。这是对FITPACK的FORTRAN例程insert的封装。

参数:
x (u)浮动

要在其中插入新结的结值。如果 tck 是从 splprep 返回的,则应给出参数值 u。

tck : 一个 BSpline 实例或一个元组a BSpline instance or a tuple

如果是元组,则预期它是一个包含节点向量、B样条系数和样条次数的元组 (t,c,k)。

mint, 可选

插入给定节点(其重数)的次数。默认值为1。

int, 可选

如果非零,输入的样条曲线被视为周期性的。

返回:
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 对象。

注释

基于 [1][2] 中的算法。

不建议直接操作 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.])