[Numpy-discussion] Bug with MA and reduce?

Eric Firing efiring@hawaii....
Fri Jul 27 13:05:21 CDT 2007


Ludwig M Brinckmann wrote:
> This is a follow-up to an earlier mail that reported a suspected bug in 
> the reduce/minimum operation of numpy.ma <http://numpy.ma>.
> 
> I have tried the same code with the scipy sandbox maskedarray 
> implementation and that gives me the correct output. For comparison:

Yes, I think I see where the bug is coming from in numpy.ma; it is 
assigning fill values for min and max operations as if all integer types 
were the system default integer.
Maskedarray uses a dictionary to assign fill values for these 
operations, so it correctly takes into account the type.

Maskedarray has had much more recent development and maintenance than 
ma, and may replace it in numpy 1.1.  I have not seen any objections to 
this proposal.  From my standpoint, the sooner it happens, the 
better--unless someone raises a fundamental objection to the approach 
maskedarray is taking.

Eric

> 
> # import numpy.core.ma <http://numpy.core.ma> as MA
> import maskedarray as MA
> shape = (100)
> data = numpy.ones(shape, numpy.int16)
> data[2:40] = 3
> data[45:70] = -999
> mask = MA.make_mask_none (data.shape)
> mask[data == -999] = True
> ma = MA.MaskedArray(data, mask = mask)
> min = MA.minimum.reduce(ma,0)
> print min
> 
> With maskedarray I get, as expected 1, with numpy.core.ma 
> <http://numpy.core.ma> I get -1, a value that is not in the array.
> 
> I am using Python 2.44 on XP, the maskedarray is the svn latest, the 
> numpy.core.ma <http://numpy.core.ma> was 1.0.2, but I have tested it 
> with only the current svn version of ma.py and it produces the wrong output.
> 
> 
> Ludwig
> 
> 
> 
> On 27/07/07, *Ludwig M Brinckmann* <ludwigbrinckmann@gmail.com 
> <mailto:ludwigbrinckmann@gmail.com>> wrote:
> 
>     I have ma.minimum.reduce return a minimum value that does not exist
>     in the array.
> 
>     The following code prints -1 as the minimum of the MA, I believe it
>     should be 1.
> 
>     import numpy
>     shape = (100)
>     data = numpy.ones (shape, numpy.int16)
>     data[2:40] = 3  # dummy data
>     data[45:70] = -999 # null values
>     mask = numpy.ma.make_mask_none(data.shape)
>     mask[data == -999] = True
>     ma = numpy.ma.MaskedArray(data, mask = mask)
>     min = numpy.ma.minimum.reduce(ma,0)
>     print min
> 
>     Am I doing something really stupid here?
> 
>     Ludwig
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the Numpy-discussion mailing list