[Numpy-discussion] numarray.sum should raise exception for wrong axis argument - and slicing ...
Sebastian Haase
haase at msg.ucsf.edu
Fri Jun 25 08:24:07 CDT 2004
On Friday 25 June 2004 05:48 am, Todd Miller wrote:
> On Wed, 2004-06-23 at 18:06, Sebastian Haase wrote:
> > 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 ?
>
> This is a bug. Hopefully I'll get it today.
>
> > 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 ?
>
> This is also a bug. Fixed in CVS now.
>
> Thanks for the report!
>
> Regards,
> Todd
Thanks so much - I got worried there for a moment ;-)
Regards,
Sebastian
More information about the Numpy-discussion
mailing list