我想知道是否有一种简单的方法来在scipy中pickle一个interp1d
对象。天真的方法似乎不起作用。
import pickle
import numpy as np
from scipy.interpolate import interp1d
x = np.linspace(0,1,10)
y = np.random.rand(10)
sp = interp1d(x, y)
with open("test.pickle", "wb") as handle:
pickle.dump(sp, handle)
这会引发以下PicklingError错误:
---------------------------------------------------------------------------
PicklingError Traceback (most recent call last)
<ipython-input-1-af4e3326e7d1> in <module>()
10
11 with open("test.pickle", "wb") as handle:
---> 12 pickle.dump(sp, handle)
PicklingError: Can't pickle <function interp1d._call_linear at 0x1058abf28>: attribute lookup _call_linear on scipy.interpolate.interpolate failed
xi
和yi
数组以及关键字参数进行腌制。当反腌化时,您需要再次调用interp1d
... 如果您的目标是节省CPU功耗,则这不是一个解决方案。 - fheshwfq