1、 '='的赋值方式会带有关联性
>>> import numpy as np >>> a = np.arange(4) >>> b = a >>> c = a >>> d = b >>> a[0] = 11 >>> print(a) [11 1 2 3] #改变a的第一个值,b、c、d的第一个值也会同时改变 >>> b is a True >>> c is a True >>> d is a True #同样更改d的值,a、b、c也会改变 >>> d[1:3] = [22, 33] >>> print(a) [11 22 33 3] >>> print(b) [11 22 33 3] >>> print(c) [11 22 33 3]
2、copy()的赋值方式没有关联性
>>> b = a.copy() # deep copy >>> print(b) [11 22 33 3] >>> a[3] = 44 >>> print(a) [11 22 33 44] >>> print(b)#此时a与b已经没有关联 [11 22 33 3]