# [Numpy-discussion] numarray bug: sum, product, alltrue, sometrue

Huaiyu Zhu huaiyu_zhu at yahoo.com
Mon Sep 16 23:40:05 CDT 2002

```There is a bug in the dimension-reducing functions (sum, product,
alltrue, sometrue) in numarray: The outside swapaxes should take into
account that one axis is reduced.  The expected behavior should be:

>>> from numarray import *
>>> a = ones((2,3,4))
>>> sum(a, axis=0).shape
(3, 4)
>>> sum(a, axis=1).shape
(2, 4)
>>> sum(a, axis=2).shape
(2, 3)

A patch is attached below.

Huaiyu

*** numarray.py~	Tue Jul  2 11:12:24 2002
--- numarray.py	Mon Sep 16 23:17:27 2002
***************
*** 995,997 ****
else:
!         return swapaxes(ufunc.add.reduce(swapaxes(a, 0, axis)), 0, axis)

--- 995,997 ----
else:
!         return swapaxes(ufunc.add.reduce(swapaxes(a, 0, axis)), 0, axis-1)

***************
*** 1014,1016 ****
return swapaxes(ufunc.multiply.reduce(swapaxes(a, 0, axis)),
!                         0, axis)

--- 1014,1016 ----
return swapaxes(ufunc.multiply.reduce(swapaxes(a, 0, axis)),
!                         0, axis-1)

***************
*** 1034,1036 ****
return swapaxes(ufunc.logical_and.reduce(swapaxes(a, 0, axis)),
!                         0, axis)
def sometrue(a, axis=0):
--- 1034,1036 ----
return swapaxes(ufunc.logical_and.reduce(swapaxes(a, 0, axis)),
!                         0, axis-1)
def sometrue(a, axis=0):
***************
*** 1043,1045 ****
return swapaxes(ufunc.logical_or.reduce(swapaxes(a, 0, axis)),
!                         0, axis)

--- 1043,1045 ----
return swapaxes(ufunc.logical_or.reduce(swapaxes(a, 0, axis)),
!                         0, axis-1)

```