import numpy as np
arr1 = np.array([1,2,3])#浅拷贝,arr1和arr2共享一块内存
arr2 = arr1
arr2[0] = 5
print(arr1)
print(arr2)
out:
[5 2 3]
[5 2 3]
arr3 = arr1.copy()#深拷贝
arr3[0] = 10
print(arr1)
print(arr3)
out:
[5 2 3]
[10 2 3]
import numpy as np
arr1 = np.array([1,2,3])#浅拷贝,arr1和arr2共享一块内存
arr2 = arr1
arr2[0] = 5
print(arr1)
print(arr2)
out:
[5 2 3]
[5 2 3]
arr3 = arr1.copy()#深拷贝
arr3[0] = 10
print(arr1)
print(arr3)
out:
[5 2 3]
[10 2 3]