Back to NumPy Notes
Topic #8

NumPy Copy vs View


The Difference Between Copy and View

The main difference between a copy and a view of an array is that the copy is a new array, and the view is just a view of the original array.

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 affect the copy.

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 array will affect the view.


COPY:

Example

  import numpy as np

arr = np.array([1, 2, 3, 4, 5])
x = arr.copy()
  arr[0] = 42

print(arr)
print(x)

Note: The copy SHOULD NOT be affected by the changes made to the original array.


VIEW:

Example

  import numpy as np

arr = np.array([1, 2, 3, 4, 5])
x = arr.view()
arr[0] = 42

print(arr)
print(x)

Note: The view SHOULD be affected by the changes made to the original array.

Make Changes in the VIEW:

Example

  import numpy as np

arr = np.array([1, 2, 3, 4, 5])
x = arr.view()
  x[0] = 31

print(arr)
print(x)

Note: The original array SHOULD be affected by the changes made to the view.


Check if Array Owns its Data

As mentioned above, copies owns the data, and views does not own the data, but how can 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.

Example

  import numpy as np

arr = np.array([1, 2, 3, 4, 5])

x = arr.copy()
  y = arr.view()

print(x.base)
print(y.base)

Note: The copy returns None. The view returns the original array.

Want to go beyond the notes?

Join Coding Now Tech Institute's NumPy course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

NumPy Copy vs View – FAQs

Quick answers about learning NumPy Copy vs View in NumPy.

This free note from Coding Now Tech Institute explains NumPy Copy vs View in NumPy — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every NumPy topic on Coding Now Tech Institute, including NumPy Copy vs View, is 100% free with no signup required.
With focused practice, most students grasp NumPy Copy vs View in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now