[issue39864] IndexError gives wrong axis info

Peter Otten report at bugs.python.org
Thu Mar 5 10:42:26 EST 2020


Peter Otten <__peter__ at web.de> added the comment:

This is not a bug (and if it were you would have to report to numpy, not cpython).

Consider:

>>> import numpy
>>> a = numpy.zeros((2,2,2))
>>> a[0,2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: index 2 is out of bounds for axis 1 with size 2

This is probably the message you expect. However, if you write
>>> a[0][2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: index 2 is out of bounds for axis 0 with size 2

you split the operation into two steps, and the second axis of a is effectively the first axis of a[0].

----------
nosy: +peter.otten -steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39864>
_______________________________________


More information about the Python-bugs-list mailing list