【发布时间】:2016-04-21 02:23:09
【问题描述】:
我想将scipy.interpolate.InterpolatedUnivariateSpline生成的对象interpolator保存到一个文件中,以便之后加载并使用它。
这是控制台上的结果:
>>> interpolator
<scipy.interpolate.fitpack2.InterpolatedUnivariateSpline object at 0x11C27170>
np.save("interpolator",np.array(interpolator))
>>> f = np.load("interpolator.npy")
>>> f
array(<scipy.interpolate.fitpack2.InterpolatedUnivariateSpline object at 0x11C08FB0>, dtype=object)
这些是尝试使用具有通用值的加载插值器f 的结果:
>>>f(10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'numpy.ndarray' object is not callable
或:
>>> f[0](10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: too many indices for array
如何正确保存/加载它?
【问题讨论】:
-
它在一个 0d 数组中。试试
f[()]或f.item()。
标签: python numpy scipy interpolation