[Numpy-discussion] Re: numarray-BUG in arr.maximum.reduce: negative axis returns "transpose"
Robert Kern
robert.kern at gmail.com
Wed Mar 22 08:20:07 CST 2006
Paul Barrett wrote:
> On 3/21/06, *Sebastian Haase* <haase at msg.ucsf.edu
> <mailto:haase at msg.ucsf.edu>> wrote:
>
> Hi,
> I think I discovered another "ugly" bug:
> If have an array with rank 4. I thought
> numarray.maximum.reduce(arr, 1)
> would be identical to
> .numarray.maximum.reduce(arr, -3)
> But instead I get something that looks more like the transpose of
> the first !
> I tried to check the documentation for the numarray.maximum function,
> but there is none at [8. Array Functions
> http://stsdas.stsci.edu/numarray/numarray-1.5.html/node38.html
> <http://stsdas.stsci.edu/numarray/numarray-1.5.html/node38.html>]
>
> This is a test a ran afterwards:
> >>> q=na.arange(8)
> >>> q.shape = (2,2,2)
> >>> q
> [[[0 1]
> [2 3]]
> [[4 5]
> [6 7]]]
> >>> na.maximum.reduce(q)
> [[4 5]
> [6 7]]
> >>> na.maximum.reduce(q,0)
> [[4 5]
> [6 7]]
> >>> na.maximum.reduce(q,1)
> [[2 3]
> [6 7]]
> >>> na.maximum.reduce(q,-1)
> [[1 3]
> [5 7]]
>
> So its not really the transpose - but in any case it's something
> strange...
>
> 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.
Well, there is at least an incompatibility with numpy and Numeric.
In [6]: def test(mod):
...: q = mod.reshape(mod.arange(16), (2,2,2,2))
...: for i in range(4):
...: mask = (mod.maximum.reduce(q, i) == mod.maximum.reduce(q, i-4))
...: print i, mod.alltrue(mod.ravel(mask))
...:
...:
In [7]: test(numpy)
0 True
1 True
2 True
3 True
In [8]: test(numarray)
0 0
1 0
2 1
3 1
In [19]: test(Numeric)
0 1
1 1
2 1
3 1
In [9]: numpy.__version__
Out[9]: '0.9.6.2148'
In [10]: numarray.__version__
Out[10]: '1.5.0'
In [20]: Numeric.__version__
Out[20]: '24.0'
--
Robert Kern
robert.kern at gmail.com
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion
mailing list