[Numpy-discussion] better error message possible?

Paul Anton Letnes paul.anton.letnes at gmail.com
Thu Jun 7 05:32:53 EDT 2012


On 7. juni 2012, at 10:30, Thouis (Ray) Jones wrote:

> I've opened a PR at https://github.com/numpy/numpy/pull/296 for discussion.
> 
> A typical result
> 
>>>> np.zeros((3,3))[[1,2,3]]
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> IndexError: index 3 is out of bounds for axis 0: [-3,3)
> 
> Ray Jones
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


I would prefer:
IndexError: index 3 is out of bounds for axis 0: [-3,2]
as I find the 3) notation a bit weird - after all, indices are not floats, so 2.999 or 2.3 doesn't make sense as an index.

An alternative is to not refer to negative indices and say
IndexError: index 3 is out of bounds for axis 0, shape was: (3,)
(print more axes when the number of axes is higher.)

BTW, I'm really glad someone is taking an interest in these error messages, it's a great idea!

Paul


More information about the NumPy-Discussion mailing list