Today, when I used the slice operator to modify an array, I found that the following operations got different results, although operations seemed to be the same.
import numpy as np
a = np.array([[1,2,3],[0,5,4],[4,5,3],[5,8,7]])
print(a)
a[[0,1],:][0:2,:] = [[11,12,13],[8,9,7]]
print(a)
a[0:2,:][[0,1],:] = [[11,12,13],[8,9,7]]
print(a)
the results are following:
[[1 2 3]
[0 5 4]
[4 5 3]
[5 8 7]]
[[1 2 3]
[0 5 4]
[4 5 3]
[5 8 7]]
[[11 12 13]
[8 9 7]
[4 5 3]
[5 8 7]]
I guess that "a[[0,1],:]" creates a new array, and "a[0:2,:]" doesn't. But why? I am confused. I want to know under what conditions a new array will be created when I use the slice operator.