Serializing a Numpy Array Tuple

I have a pair of numpy matrices (more precisely 3-dimensional) that are stored in tuples

(a1,b1,c1)
(a2,b2,c2)
...
(an,bn,cn)

I would like to serialize each tuple into a file that can be read in Python on another computer (Linux => Windows, both x86-64). What would be a pythonic way to accomplish this?

+3
source share
4 answers

numpy.savez or numpy.savez_compressed is the path. I heard, but never experienced, problems with some types of arrays that didn’t poison well.

I recall this post (it seems not too much), and also something about numpy.void not etching . This is probably not a problem, but it is.

+6
source

shelve, pickle, cPickle, shove. python ; shove shelve , , shove , . , , , . SQLAlchemy.

, . pickle shelve, .

+1

Usually I use cPickle, although I did not make a formal comparison with other methods. In addition, I always write the file as binary and use the highest protocol setting:

f = open('fname.pkl','wb')
cPickle.dump(array_tuple,f,-1)
f.close()
+1
source

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


All Articles