[Numpy-discussion] maxima of masked arrays
George Nurser
agn at noc.soton.ac.uk
Fri Feb 17 06:37:02 EST 2006
I am trying to get the n-1 dimensional array of maxima of an array
taken over a given axis.
with ordinary arrays this works fine.
E.g.
In [49]: a = arange(1,13).reshape(3,4)
In [50]: a
Out[50]:
array([[ 1, 2, 3, 4],
[ 5, 6, 7, 8],
[ 9, 10, 11, 12]])
The maximum over all elements is:
In [51]: print a.max()
12
& the array of maxima over the 0-axis is OK too:
In [52]: print a.max(0)
[ 9 10 11 12]
But with a masked array there are problems.
In [54]: amask = ma.masked_where(a < 5,a)
In [55]: amask
Out[55]:
array(data =
[[999999 999999 999999 999999]
[ 5 6 7 8]
[ 9 10 11 12]],
mask =
[[True True True True]
[False False False False]
[False False False False]],
fill_value=999999)
The maximum over all elements is fine:
In [56]: amask.max()
Out[56]: 12
but trying to get an array of maxima over the 0-axis fails:
n [57]: amask.max(0)
Out[57]:
array(data =
[[999999 999999 999999 999999]
[ 5 6 7 8]
[ 9 10 11 12]],
mask =
[[True True True True]
.......
Are there any workarounds for this?
-George.
More information about the NumPy-Discussion
mailing list