I have a class defined as:
class A():
def __init__():
self.a = np.array([0,1,2,3,4,5])
self.b = self.a.reshape((2, 3))
now, b is in fact a reshaped reference of array a. If we change the first element of a:a[0] = 10
, b[0, 0]
will also change to 10.
I use cPickle to save this array, however, when I load the dump. a and b become different array. I want to know whether there are any method to make b still the reference of a?
the latest prerelease of jsonpickle does correctly serialize numpy views; pickle sadly does not.
You can use
__getstate__
and__setstate__
to control the pickle: