numpy - Python: Making sense of references -


i understand basic python references difference between a+=b , a=a+b, confuses me.

import numpy np arr1 = np.arange(6).reshape(2,3) arr2 = arr1[0] arr2 arr1[0] #returns false, when expect true arr1[0] = [7,8,9] arr2 #[7,8,9], when expect [0,1,2] since 'is' returned false 

what's going on here?

when index numpy array, create new view (which numpy array). different object, is fails, it's view of same piece of honestly-actually-on-the-hardware memory. when modify view, therefore modify bit of memory of there may view.

edit: can see start address of memory associated numpy array inspecting ctypes.data attribute of array.

in [1]: import numpy np  in [2]: arr1 = np.arange(6).reshape(2,3)  in [3]: arr2 = arr1[0]  in [4]: arr2.ctypes.data out[4]: 39390224  in [5]: arr1[0].ctypes.data out[5]: 39390224 

the same!


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -