获取 SciPy CubicSpline 的中间点
Get intermediate points of SciPy CubicSpline
我试图在 SciPy 中进行插值后获取一组中间点。但是似乎没有任何直接的方法可以做到这一点。有人可以帮忙吗?
示例代码:
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
x = np.arange(10)
y = np.sin(x)
cs = CubicSpline(x, y)
xs = np.arange(-0.5, 9.6, 0.1)
plt.figure(figsize=(6.5, 4))
plt.plot(x, y, 'o', label='data')
plt.plot(xs, np.sin(xs), label='true')
plt.plot(xs, cs(xs), label="S")
plt.plot(xs, cs(xs, 1), label="S'")
plt.plot(xs, cs(xs, 2), label="S''")
plt.plot(xs, cs(xs, 3), label="S'''")
plt.xlim(-0.5, 9.5)
plt.legend(loc='lower left', ncol=2)
plt.show()
作为CubicSpline documentation says,它returns的对象是可调用的,带参数
- x : array_like
Points to evaluate the interpolant at.
- nu : int, optional
Order of derivative to evaluate.
- extrapolate : {bool, ‘periodic’, None}, optional
因此,cs(5)
给出样条曲线在 5 处的值,而 cs(5, 2)
是其在 5 处的二阶导数,依此类推。
我试图在 SciPy 中进行插值后获取一组中间点。但是似乎没有任何直接的方法可以做到这一点。有人可以帮忙吗?
示例代码:
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
x = np.arange(10)
y = np.sin(x)
cs = CubicSpline(x, y)
xs = np.arange(-0.5, 9.6, 0.1)
plt.figure(figsize=(6.5, 4))
plt.plot(x, y, 'o', label='data')
plt.plot(xs, np.sin(xs), label='true')
plt.plot(xs, cs(xs), label="S")
plt.plot(xs, cs(xs, 1), label="S'")
plt.plot(xs, cs(xs, 2), label="S''")
plt.plot(xs, cs(xs, 3), label="S'''")
plt.xlim(-0.5, 9.5)
plt.legend(loc='lower left', ncol=2)
plt.show()
作为CubicSpline documentation says,它returns的对象是可调用的,带参数
- x : array_like
Points to evaluate the interpolant at.- nu : int, optional
Order of derivative to evaluate.- extrapolate : {bool, ‘periodic’, None}, optional
因此,cs(5)
给出样条曲线在 5 处的值,而 cs(5, 2)
是其在 5 处的二阶导数,依此类推。