Difference Between Copy and View in NumPy Array
The main difference between copy and view is in copy its just copy of original array and in view its just view of the original array.
Copy
In copy if we make any changes in the original it will not effect on the copy array and vice versa.
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
arrCopy = arr.copy()
arr[0] = 6
print(arr)
print(arrCopy)
-----------------------
Output
-----------------------
[6 2 3 4 5]
[1 2 3 4 5]From the above code you can see we change some changes in the original array but its not effects on the copied array.
View
The view doesn't own any datas so If we change any changes in view it will effect on original array and vise versa.
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
arrView = arr.view()
arr[0] = 6
print(arr)
print(arrView)
-----------------------
Output
-----------------------
[6 2 3 4 5]
[6 2 3 4 5]From the above code you can see we change some changes in the original array and its effects on the view too. If we change the changes in view then also the output will be same as original.
Also you can check the base of the array then you can confirm that the view doesn't own the data. That's why the data will be same