In the docs, it says (emphasis mine):
Advanced indexing is triggered when the selection object, obj, is a
non-tuple sequence object, an ndarray (of data type integer or bool),
or a tuple with at least one sequence object or ndarray (of data type
integer or bool). There are two types of advanced indexing: integer
and Boolean.
<snip>
Also recognize that x[[1,2,3]]
will trigger advanced indexing, whereas
x[[1,2,slice(None)]]
will trigger basic slicing.
I know why x[(1, 2, slice(None))]
triggers basic slicing. But why does x[[1,2,slice(None)]]
trigger basic slicing, when [1,2,slice(None)]
meets the condition of being a non-tuple sequence?
On a related note, why does the following occur?
>>> a = np.eye(4)
>>> a[(1, 2)] # basic indexing, as expected
0.0
>>> a[(1, np.array(2))] # basic indexing, as expected
0.0
>>> a[[1, 2]] # advanced indexing, as expected
array([[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.]])
>>> a[[1, np.array(2)]] # basic indexing!!??
0.0
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…