This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IndexError gives wrong axis info
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: ningyidu, peter.otten
Priority: normal Keywords:

Created on 2020-03-05 15:06 by ningyidu, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg363433 - (view) Author: Ningyi Du (ningyidu) Date: 2020-03-05 15:06
IndexError: index 11 is out of bounds for axis 0 with size 11

The actual error is not with axis 0, but axis 3.

error message:
    168                     if iJ>=9:
    169                         print(iE,iE0,iEtemp,iJ,li,lf,mlf+lf)
--> 170                     SS[iEtemp][iJ][li][lf][mlf+lf]= FF(jf,mf,lf,mlf,ji,mi,li,J)*SJ[iCh][jCh]
    171 
    172                 sumSJ1 += np.abs(SJ0[iCh][jCh])**2

IndexError: index 11 is out of bounds for axis 0 with size 11
msg363434 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-03-05 15:18
Please include a sample script to reproduce the program along with a description of why you think it's an error in CPython. This seems to be a custom exception raised by a library.
msg363435 - (view) Author: Ningyi Du (ningyidu) Date: 2020-03-05 15:19
This is a simple test:

test=np.zeros((2,3,4))
print(test[1][3][1])

IndexError                                Traceback (most recent call last)
<ipython-input-13-61c3cf4c90fc> in <module>
      1 test=np.zeros((2,3,4))
----> 2 print(test[1][3][1])

IndexError: index 3 is out of bounds for axis 0 with size 3
msg363436 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-03-05 15:41
This is a numpy issue, you will need to report it to the numpy developers. But first you need to check that it really is a bug. What makes you think it is a bug? In your example, index 3 looks out of bounds to me. Remember that indexes start at 0, not 1.

In any case, this has nothing to do with us, numpy is an independent project, you will need to report it to them.
msg363437 - (view) Author: Peter Otten (peter.otten) * Date: 2020-03-05 15:42
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].
msg363474 - (view) Author: Ningyi Du (ningyidu) Date: 2020-03-06 02:25
I believe it's a bug. The axis 0 is misleading.  However, it is a problem
for numpy developers. Thank you for your time.

On Thu, Mar 5, 2020, 10:42 AM Peter Otten <report@bugs.python.org> wrote:

>
> Peter Otten <__peter__@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@bugs.python.org>
> <https://bugs.python.org/issue39864>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84045
2020-03-06 02:25:56ningyidusetmessages: + msg363474
title: IndexError gives wrong axis info -> IndexError gives wrong axis info
2020-03-05 15:42:26peter.ottensetnosy: + peter.otten, - steven.daprano
messages: + msg363437
2020-03-05 15:41:24steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg363436

resolution: third party
stage: resolved
2020-03-05 15:19:30ningyidusetnosy: - xtreak
messages: + msg363435
2020-03-05 15:18:35xtreaksetnosy: + xtreak
messages: + msg363434
2020-03-05 15:06:50ningyiducreate