Skip to content
Justice Tech School

Copies and Views

Slices are views that share memory. copy makes independent data.

Example
a = np.arange(5)
v = a[1:4]
v[0] = 99
print(a)
c = a[1:4].copy()
c[0] = 0
print(a)

Result

[ 0 99  2  3  4]
[ 0 99  2  3  4]

Exercise

Independent data.

a.()

Quiz Test

Does a slice copy data?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.