How to expand numpy inf objects?

When trying to sort an Inf object as defined in numpy (I think) dumping goes Ok, but 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'>

Why? And what's more, is there a way to fix this? I want to pickle something that has Inf in it - changing it to something else will remove the grace of the program ...

thanks

+3
source share
2 answers

If you specify a brine protocol greater than zero, it will work. The protocol is often indicated as -1, i.e. the last and largest protocol is used:

>>> 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.
+5
source

Try this solution in SourceForge that will work for any arbitrary Python object:

y_serial.py module :: Python object store with SQLite

" + :: , Python SQLite, - SQL. " " ."

http://yserial.sourceforge.net

-1

Source: https://habr.com/ru/post/1714689/


All Articles