如何腌制numpy的Inf对象? [英] How to pickle numpy's Inf objects?

查看:62
本文介绍了如何腌制numpy的Inf对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试按numpy(我认为)中的方法腌制对象Inf时,转储顺利,但加载失败:

When trying to pickle the object Inf as defined in numpy (I think), the dumping goes Ok but the loading fails:

>>> cPickle.dump(Inf, file("c:/temp/a.pcl",'wb'))
>>> cPickle.load(file("c:/temp/a.pcl",'rb'))
Traceback (most recent call last):
  File "<pyshell#257>", line 1, in <module>
    cPickle.load(file("c:/temp/a.pcl",'rb'))
ValueError: could not convert string to float
>>> type(Inf)
<type 'float'>

那是为什么? 而且-有解决此问题的方法吗?我想给其中包含Inf的内容腌制-将其更改为其他内容会破坏程序的高雅性...

Why is that? And moreover - is there a way to fix that? I want to pickle something that has Inf in it - changing it to something else will flaw the elegance of the program...

谢谢

推荐答案

如果您指定的腌制协议大于零,则该协议将起作用.协议通常指定为-1,这意味着使用最新和最大的协议:

If you specify a pickle protocol more than zero, it will work. Protocol is often specified as -1, meaning use the latest and greatest protocol:

>>> cPickle.dump(Inf, file("c:/temp/a.pcl",'wb'), -1)
>>> cPickle.load(file("c:/temp/a.pcl",'rb'))
1.#INF                   -- may be platform dependent what prints here.

这篇关于如何腌制numpy的Inf对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆