样条曲线插值



我很难在以下集合上执行样条插值:

import numpy
SOURCE = numpy.array([[1,2,3],[3,4,5], [9,10,11]])
from scipy.interpolate import griddata
from scipy.interpolate import interp1d
input = [0.5,2,3,6,9,15]

线性插值效果很好,但当我用三次插值代替线性插值时,我有一个错误:

f = interp1d(SOURCE[:,0], SOURCE[:,1:], kind="linear", axis=0, bounds_error=False)
f(input)
f = interp1d(SOURCE[:,0], SOURCE[:,1:], kind="cubic", axis=0, bounds_error=False)
ValueError: The number of derivatives at boundaries does not match: expected 1, got 0+0

如何执行此三次插值?

您的SOURCE数据太短。三次样条曲线至少需要四个点进行插值,但只能提供三个点。如果您向SOURCE再添加一个值,它应该或多或少按预期工作:

>>> SOURCE = numpy.array([[1,2,3],[3,4,5], [9,10,11], [12,13,14]])  # added an extra value
>>> f = interp1d(SOURCE[:,0], SOURCE[:,1:], kind="cubic", axis=0, bounds_error=False)
>>> f(input)
array([[nan, nan],
[ 3.,  4.],
[ 4.,  5.],
[ 7.,  8.],
[10., 11.],
[nan, nan]])

相关内容

  • 没有找到相关文章

最新更新