[Numpy-discussion] Numpy 1.4 MaskedArray bug?

Pierre GM pgmdevlist at gmail.com
Tue Jan 12 12:51:08 EST 2010


On Jan 12, 2010, at 10:52 AM, <stephen.pascoe at stfc.ac.uk> <stephen.pascoe at stfc.ac.uk> wrote:
> We have noticed the MaskedArray implementation in numpy-1.4.0 breaks
> some of our code.  For instance we see the following:

My, that's embarrassing. Sorry for the inconvenience.



> 
> in 1.3.0:
> 
>>>> a = numpy.ma.MaskedArray([[1,2,3],[4,5,6]])
>>>> numpy.ma.sum(a, 1)
> masked_array(data = [ 6 15],
> mask = False,
> fill_value = 999999)
> 
> in 1.4.0
> 
>>>> a = numpy.ma.MaskedArray([[1,2,3],[4,5,6]])
>>>> numpy.ma.sum(a, 1)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File
> "/usr/lib64/python2.5/site-packages/numpy-1.4.0-py2.5-linux-x86_64.egg/n
> umpy/ma/core.py", line 5682, in __call__
>    return method(*args, **params)
>  File
> "/usr/lib64/python2.5/site-packages/numpy-1.4.0-py2.5-linux-x86_64.egg/n
> umpy/ma/core.py", line 4357, in sum
>    newmask = _mask.all(axis=axis)
> ValueError: axis(=1) out of bounds

Confirmed.
Before I take full blame for it, can you try the following on both 1.3 and 1.4 ?
>>> np.array(False).all().sum(1)

Back to your problem: I'll fix that ASAIC, but it'll be on the SVN. Meanwhile, you can:
* Use -1 instead of 1 for your axis.
* Force the definition of a mask when you define your array with masked_array(...,mask=False)







More information about the NumPy-Discussion mailing list