In [1]:
import numpy as np
#Simple assignments make no copy of array objects or of their data.
a = np.arange(12)
b = a
# a and b are two names for the same ndarray object
print(b is a)
b.shape = (3,4)
print (a.shape)
print (id(a))
print (id(b))
In [2]:
#The view method creates a new array object that looks at the same data.
c = a.view()
print (c is a)
c.shape = (2,6)
print (a.shape)
c[0,4] = 1234
print(c)
print(a)
In [3]:
#The copy method makes a complete copy of the array and its data.
d = a.copy()
print (d is a)
d[0,0] = 9999
print (d)
print (a)