Skip to content

BUG: 3-rank tensor flips axis depending on indexing format #29453

@vwagner99

Description

@vwagner99

Describe the issue:

np.version = 2.3.2

GE.shape = (2, 3, 2) <- 3rd (numeric) rank tensor
E = [False, True]

depending on indexing syntax produces inconsistent result
GE[0,:,E] = [[0 0 1]]
GE[0][:,E] = [[0]
[0]
[1]]

has shape error: GE[0,:,E].shape = (1, 3)
vs correct shape via GE[0][:,E].shape = (3, 1)

Reproduce the code example:

import numpy as np
print("np.__version__ = ", np.__version__)
GE = np.moveaxis( np.asarray([((0,0,0), (0,0,2)), ((0,0,1), (0,1,0)), ]), 0, 2 )
E  = [False, True]
print("GE.shape = ", GE.shape)
print("E  = ", E)
print()
print("GE[0,:,E] = ", GE[0,:,E])
print("GE[0][:,E] = ", GE[0][:,E])
print(f"has shape error: GE[0,:,E].shape = {GE[0,:,E].shape}  vs correct shape via  GE[0][:,E].shape = {GE[0][:,E].shape}")

Error message:

there is no error message, just the result is wrong(?)

Python and NumPy Versions:

2.3.2
3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0]

Runtime Environment:

ubuntu 24.04.2 LTS (<- cat /etc/os-release )
Python 3.12.3 (<- python --version )

Context for the issue:

obtain unexpected wrong shape of matrix in calculation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions