Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize a tuple of numpy arrays

I have a couple of numpy matrices (3-dimensional to be exact) which 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 back into Python on another machine (Linux => Windows, both are x86-64). What would be a pythonic way to accomplish this?

like image 204
Dat Chu Avatar asked Jan 21 '23 08:01

Dat Chu


2 Answers

numpy.savez or numpy.savez_compressed is the way to go. I've heard, but never experienced issues with certain types of arrays not pickling well.

I'm recalling this post (doesn't seem to have been much of an issue) as well as something about numpy.void not pickling. Likely not an issue, but there it is.

like image 126
Paul Avatar answered Jan 23 '23 00:01

Paul


Pickle will probably work well

I also saw this: http://thsant.blogspot.com/2007/11/saving-numpy-arrays-which-is-fastest.html

like image 44
dfb Avatar answered Jan 23 '23 00:01

dfb