Numpy Copy and View

Sumangali Tamilselvan
The Startup
Published in
2 min readJul 18, 2020

--

While executing the functions, some of them return a copy of the input array, while some return the view.

When the contents are physically stored in another location, it is called Copy. On the other hand, a different view of the same memory content, we call it as View.

Copy:

The copy owns the data and any changes made to the copy will not affect original array, and any changes made to the original array will not be affected to the copy.

View:

The view does not own the data and any changes made to the view will affect the original array, and any changes made to the original will affect the view.

Copy and View of an array

As mentioned above, copy owns the data, and view does not own the data, but how do we check this?

Every NumPy array has the attribute base that returns none if the array owns the data.

Otherwise, the base attribute refers to the original object.

Checking if the copy and view owns the data or not

In simple terms, Copy is a new array and View is just a quick look of the original array.

With this we have come to the end of this article.

Happy coding….😊😊😊

--

--