1
>> np.arange(24).reshape(2,3,4)[0,:,[2,3]].shape
(2,3)
>> np.arange(24).reshape(2,3,4)[0,[1,2],:].shape
(2,4)

I get the second one, but why the first one is not (3,2)?

In the first case, the first two indices (0 and :) are basic indexing, and the last one ([2,3]) is advanced indexing.

According to the guide, deal with the basic indexing first (producing (3,4)-shaped view), then with advanced indexing it would get (3,2)-shaped copy. It looks like the single integer index (0) becomes advanced indexing, which makes no sense.

halfer
  • 19,824
  • 17
  • 99
  • 186
Brainor
  • 350
  • 2
  • 10
  • 2
    I had the exact same problem once, Does this answer your question?https://stackoverflow.com/a/72410804/3896008 – lifezbeautiful May 24 '23 at 12:26
  • @lifezbeautiful jesus the questions are identical, and I REALLY did searched for it but failed. – Brainor May 24 '23 at 12:31
  • I get it for the `x[[[0],[1]],:,[0,1,2,3]]` case in the [answer](https://stackoverflow.com/a/72410804/3896008), because the first indice is advanced indexing; the `a[1, :, :, [2,3,4]]` case can be acceptable only if we consider the single int indice as advanced indexing. Anyway, thank @lifezbeautiful and @hpaulj for your help :) – Brainor May 24 '23 at 12:41

0 Answers0