numpy
numpy copied to clipboard
BUG: subarray of a 4D array changed the order of axis
Describe the issue:
In [1]: import numpy as np
In [2]: a=np.zeros((2,3,4,5))
In [3]: a.shape Out[3]: (2, 3, 4, 5)
In [4]: a[:, [True, False, False], :, :].shape Out[4]: (2, 1, 4, 5)
In [5]: a[:, [True, False, False], :, 0].shape Out[5]: (1, 2, 4) <-- look here, should it be (2, 1, 4)?
In [6]: a[:, [1], :, 0].shape Out[6]: (1, 2, 4) <-- look here
Reproduce the code example:
import numpy as np
a=np.zeros((2,3,4,5))
print(a[:, [True, False, False], :, 0]).shape
output (1, 2, 4)
Error message:
No response
Python and NumPy Versions:
2.0.0 3.9.18 (main, Sep 7 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)]
Runtime Environment:
No response
Context for the issue:
No response
I think this is similar to #26184, should look into Advanced Indexing and Mixed Indexing
@EngineerEricXie pointed to the right explanations, thanks. Closing.