1.a = b b of id is copied to b, and a and b are the same object
1 import numpy as np 2 3 a = np.arange(5) 4 print(a) 5 b = a 6 print(id(a)) 7 print(id(b))
The results can be seen by running the diagram, a is equal to b of id id, with a pointed object.
2. b = a.view () is a shallow copy, b and a are different objects, but they are shared elements
1 import numpy as np 2 3 a = np.arange(5) 4 print(a) 5 b = a.view() 6 print(id(a)) 7 print(id(b)) 8 b[0] = -1 9 print(a)
The results can be seen by running the following figure, a and b are different objects, but when I change a time element, b element also changed. '