numpy: slice b = a[1:3]; b[0] = 99 also changes a (view); use a[1:3].copy() to avoid
@aiden-f-dsouza▲ 7 net votes
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.