[Matrix-SIG] pickling of arrays
David Ascher
da@skivs.ski.org
Tue, 24 Mar 1998 10:10:22 -0800 (PST)
FYI, The following addition to Numeric.py will allow arrays to pickle
without needing to subclass Pickler. Still inefficient, but helpful for
non-huge arrays.
--david
import copy_reg
def array_constructor(shape, typecode, thestr):
x = fromstring(thestr, typecode)
x.shape = shape
return x
def pickle_array(a):
return array_constructor, (a.shape, a.typecode(), a.tostring(),)
copy_reg.pickle(ArrayType, pickle_array, array_constructor)