下面的代碼顯示,當你醃製兩個對象時,當一個是另一個的引用(是否是正確的單詞?),在你醃製並加載該關係後丟失。在下面,您可以看到aa
中的更改也發生在bb
中。但是,在對相同行爲進行醃製和測試之後,我預計dd
的變化也會發生在ee
中。但這種情況並非如此。你能解釋一下發生了什麼嗎?Wy是不考慮可變/引用對象的泡菜?
import numpy as np
aa=np.ones((5,3))
print 'aa',aa
bb=aa.T
aa[2,2]=3
print 'aa',aa, aa.nbytes
print 'bb', bb, bb.nbytes #bb also prints out hte affect of the change from aa. OK
import pickle
pickle.dump([aa,bb], open("save.p", "wb"))
with open("save.p", "rb") as f:
dd,ee=pickle.load(f)
print 'dd',dd
print 'ee',ee
dd[1,0]=5 #shouldn't this affect ee also?
print 'dd',dd
print 'ee',ee # is different than dd. I would have expected that they should be the same (except for the transpose).