【发布时间】:2019-04-03 22:45:32
【问题描述】:
我想知道是否有一种简单的方法可以在 scipy 中腌制 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
【问题讨论】: