Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

NumPy Array Copy vs View

The Difference Between Copy and View

The main difference between a copy and a view of an array is that a copy creates a new array that owns its data, meaning changes to the copy do not affect the original array, while a view is a reference to the original array, so modifications to the view will impact the original, and vice versa.

COPY:

Example

Create a copy of the array, modify the original array, and then display both arrays.

import numpy as np

arr = np.array([12345])
x = arr.copy()
arr[0] = 42

print(arr)
print(x)