Copies and Views
Slices are views that share memory with the original. Changing a view changes the source. Use copy() for an independent array.
Example
import numpy as np
a = np.arange(5)
v = a[1:3]
v[0] = 99
print(a)
c = a[1:3].copy()
c[0] = 0
print(a)Result
[ 0 99 2 3 4] [ 0 99 2 3 4]
Exercise
Make an independent array.
a.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.