Python pickle : Can't pickle <class 'interpnd.LinearNDInterpolator' >: it's not found as interpnd. LinearNDInterpolator

标签 python interpolation pickle

我对 Python 中的 Pickle 模块有疑问。我想插入一些 4 参数数据,所以我想构建并存储插值器,以便可以在另一个代码中重用它,而无需在执行时重新生成。实际上,我在每次执行代码时都浪费了大量时间重新创建它。 我所能得到的就是这条消息:

"PicklingError: Can't pickle : it's not found as interpnd.LinearNDInterpolator"

我正在绞尽脑汁地试图弄清楚如何解决它,这是我的代码的简化版本(Python v2.7),回溯如下 预先感谢您的建议

a1,a2,a3,a4 = np.mgrid[paramvariation]
pts = np.array([a1.ravel(),a2.ravel(),a3.ravel(),a4.ravel()]).T
sr=paramvalues.ravel()
LinearNDInterp = interp.interpnd.LinearNDInterpolator(pts,sr,fill)

fileid=open("try.out",'w')
pickle.dump(LinearNDInterp,fileid) 
fileid.close()

Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\startup.py", line 128, in runfile
execfile(filename, glbs)
File "tryout.py", line 516, in <module>
main("")
File "tryout.py", line 354, in main
pickle.dump(LinearNDInterp,fileid)
File "C:\Python27\lib\pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 401, in save_reduce
save(args)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 562, in save_tuple
save(element)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 748, in save_global
(obj, module, name))
PicklingError: Can't pickle <class 'interpnd.LinearNDInterpolator'>: it's not found as interpnd.LinearNDInterpolator

最佳答案

看起来像是 SciPy 最近修复的错误:
BUG: interpolate: make interpnd.* objects pickleable

关于Python pickle : Can't pickle <class 'interpnd.LinearNDInterpolator' >: it's not found as interpnd. LinearNDInterpolator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9836979/

相关文章:

Javascript字符串插值给出与字符串连接不同的结果

python - 将 python matplotlib 图保存为 pickle

python - win32api.keybd_event 停止工作

python - scipy.interpolate.interp1d 'kind' 不工作

resize - VMR9无窗口的DirectShow插值(像素化)问题

Python- dill : Can't pickle decorated class

python - 如何管理 pandas 数据框中的特殊字符\r

python - 如何使用点绘制 Pandas 数据框的两列

python - Django 休息框架 : testing update action doesn't return 400 if request data is invalid

python - 比较 itertools.product 的 id