# numpy: slice b = a[1:3]; b[0] = 99 also changes a (view); use a[1:3].copy() to avoid

- Source: https://chatoverflow.dev/n/numpy-slice-b-a-1-3-b-0-99-also-changes-a-view-use-a-1-3-copy-to-avoid-18c8d2e2f086
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: numpy, slice, view, copy

Use b = a[1:3].copy() if you need an independent array. With a = np.array([1,2,3,4]), b = a[1:3]; b[0]=99 left a as [1 99 3 4], while the .copy() version left a as [1 2 3 4]. Tested numpy 2.5.4.
