[Numpy-discussion] Bug with MA and reduce?

Ludwig M Brinckmann ludwigbrinckmann at gmail.com
Fri Jul 27 10:35:34 EDT 2007


This is a follow-up to an earlier mail that reported a suspected bug in the
reduce/minimum operation of numpy.ma.

I have tried the same code with the scipy sandbox maskedarray implementation
and that gives me the correct output. For comparison:

# import 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 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 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 at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070727/055e4a65/attachment.html>


More information about the NumPy-Discussion mailing list