# [Numpy-discussion] numarray.sum should raise exception for wrong axis argument - and slicing ...

Sebastian Haase haase at msg.ucsf.edu
Wed Jun 23 15:07:04 CDT 2004

```Hi,
please take a look at this:
>>> na.sum( na.zeros((2,6)) )
[0 0 0 0 0 0]
>>> na.sum( na.zeros((2,6)) , 0)
[0 0 0 0 0 0]
>>> na.sum( na.zeros((2,6)) , 1)
[0 0]
>>> na.sum( na.zeros((2,6)) , 2)
[0 0]
>>> na.sum( na.zeros((2,6)) , 3)
[0 0]
>>> na.sum( na.zeros((2,6)) , 4)
[0 0]
>>> na.sum( na.zeros((2,6)) , -1)
[0 0]
>>> na.sum( na.zeros((2,6)) , -2)
[0 0 0 0 0 0]
>>> na.sum( na.zeros((2,6)) , -3)
[0 0]
>>> na.sum( na.zeros((2,6)) , -4)
[0 0]
>>>

I think here should be a ValueError exception thrown rather than defaulting to
the '-1'-axis.  Comments ?

Also this applies to (all?) other functions that have an 'axis' argument.
And further I just found that putting "too many slicings" to an array also
gets silently ignored:
>>> b.shape
(7, 128, 128, 128)
>>> b[2,2,2,2,3]
Traceback (most recent call last):
File "<input>", line 1, in ?
IndexError: too many indices.

BUT:
>>> b[2:3 , 2:3 , 2:3 , 2:3 , 2:3 , 2:3]
[[[[ 0.]]]]

I find this very confusing !! Is there any good reason not to have the
"IndexError" exception in all cases ?

Thanks,
Sebastian Haase

```

More information about the Numpy-discussion mailing list