[Numpy-discussion] Operations on a masked array of a scalar

Pierre GM pgmdevlist@gmail....
Tue Jun 29 12:58:41 CDT 2010

On Jun 29, 2010, at 1:41 PM, Martin Janousek wrote:

> Hi,
> I have a Python code working on MaskedArray which can produce arrays
> of a number of different shapes and ranks. In an extreme case I get
> "an array" constructed from a scalar:
> x=numpy.ma.array(333.,mask=False)
> Until the recent upgrade to Numpy 1.4.1 it has been possible to do
> operations on such an object, like x+=2. or x==444.  but now I have
> the following problem:
>>>> numpy.ma.array(333.,mask=False)==1.
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "/usr/local/apps/python/2.6/lib/python2.6/site-packages/numpy/ma/core.py",
> line 3567, in __eq__
>    check._mask = self._mask
> AttributeError: 'numpy.bool_' object has no attribute '_mask'
> The problem seems to be only with __eq__ and __ne__ operators, others
> like __gt__ are ok:
>>>> numpy.ma.array(333.,mask=False)>1.
> masked_array(data = True,
>             mask = False,
>       fill_value = True)
> For ndarray it works fine as well:
>>>> numpy.array(333.)==1.
> False
> So did I find a bug or working with a "scalar array" is considered
> dangerous and as such it should be avoided? In any case the behaviour
> of Numpy 1.4.1 compared to 1.2.1 has changed in this aspect.

That's a bug allright, sorry about that. Thought I took care of it, obviously not. Anyhow, it should be fixed in SVNr8467.

More information about the NumPy-Discussion mailing list