import numpy as np
arr1 = np.array([1,2,3])
#浅拷贝
arr2 = arr1#arr1和arr2共享一块内存
arr2[0] = 5
print(arr2)
[5 2 3]
print(arr1)
[5 2 3]
#深拷贝
arr3 = arr1.copy()
arr3[0] = 10
print(arr3)
[10 2 3]
print(arr1)
[5 2 3]
Numpy-浅拷贝和深拷贝
最新推荐文章于 2024-08-24 11:00:49 发布