[Numpy-discussion] numarray-BUG in arr.maximum.reduce: negative axis returns "transpose"

Sebastian Haase haase at msg.ucsf.edu
Wed Mar 22 09:46:01 EST 2006


On Wednesday 22 March 2006 05:32, Paul Barrett wrote:
> On 3/21/06, Sebastian Haase <haase at msg.ucsf.edu> wrote:
<snip>
>
> The above behavior for maximum.reduce looks consistent to me.
>
> The reduce axis for examples 1 and 2 above is 0, so maximum is comparing
> arrays [[0 1] [2 3]] and [[4 5] [6 7]], which gives [[4 5] [6 7]].  Example
> 3 is comparing arrays [[0 1] [4 5]] and [[2 3] [6 7]], giving [[2 3] [6
> 7]].  And the last example is comparing arrays [[0 2] [4 6]] and [[1 3] [5
> 7]], giving [[1 3] [5 7]].
>
> I think it depends on how you look at the shape of the array.
>
>  -- Paul
Sorry
I did the test wrong - 
>>> na.maximum.reduce(q,2)
[[1 3]
 [5 7]]
>>> na.maximum.reduce(q,-1)
[[1 3]
 [5 7]]
So it obviously works as advertised.

The array where I noticed the transpose behaviour was really of shape 
32,15,521,512  and my command was  na.maximum.reduce(arr,-3) which "looked" 
tranpose to what I got with na.maximum.reduce(arr,1).
I using numarray for image analysis and the array might have been a memmap-ed 
image file.  I'm just worried because I found an "accidental transpose bug" 
on type conversion a few years back (see mailing list)...
( I forgot to say that I running Python 2.2 and numarray version '1.4.0' )

I just reran the test with python2.4  and arr=arr.copy() [which should give a 
non-memmap version of arr]

>>> arrM  = na.maximum.reduce(arr,-3)
>>> arrMt = na.transpose(arrM,(0,2,1))
>>> arrM1= na.maximum.reduce(arr,1)
>>> U.mmms(arrM1-arrMt)  # returns min,max,mean,stddev
(0, 0, 0.0, 0.0)

So it definitely transposes the last two axes !  Maybe the bug shows up on 
rank >=4  !? - which is the case Robert tested.

Thanks,
Sebastian Haase




More information about the NumPy-Discussion mailing list