Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 664 Bytes

Copy Vs. View.md

File metadata and controls

25 lines (20 loc) · 664 Bytes

Copy Vs. View

Copy means a new array in NumPy. Any changes made to the copy don't affect the original array, and vice-versa. Also, copies own its data.
View is just a view of the original array. Any changes made to the view will affect the original array, and vice-versa. View doesn't own the data.

To make a copy of an array:

arr.copy()


To make a view of an array:

arr.view()


To check if an array owns its data:

arr = np.array([1,2,3,4,5])
x = arr.copy()
y = arr.view()
print(x.base)
print(y.base)

Output of copy:

None

Output of view:
[1 2 3 4 5]