import numpy as np arr1=np.array([1,2,3]) arr2=arr1 #浅拷贝,arr1和arr2共享一块内存 print(arr1) print(arr2)
[1 2 3] [1 2 3]
arr2[0]=5 print(arr1) print(arr2)
[5 2 3] [5 2 3]
arr3=arr1.copy() #深拷贝,arr3另用一个空间 print(arr3)
[5 2 3]
arr3[0]=15 print(arr1) print(arr3)
[5 2 3] [15 2 3]