[Numpy-discussion] Strange behavior in setting masked array values in Numpy 1.1.0

Tony Yu tsyu80 at gmail.com
Sat May 31 17:56:20 EDT 2008


Great job getting numpy 1.1.0 out and thanks for including the old API  
of masked arrays.

I've been playing around with some software using numpy 1.0.4 and took  
a crack at upgrading it to numpy 1.1.0, but I ran into some strange  
behavior when assigning to slices of a masked array.

I made the simplest example I could think of to show this weird  
behavior. Basically, reordering the masked array and assigning back to  
itself *on the same line* seems to work for part of the array, but  
other parts are left unchanged. In the example below, half of the  
array is assigned "properly" and the other half isn't. This problem is  
eliminated if the assignment is done with a copy of the array.  
Alternatively, this problem is eliminated if I using  
numpy.oldnumeric.ma.masked_array instead of the new masked array  
implementation.

Is this just a problem on my setup?

Thanks in advance for your help.
-Tony Yu

Example:
========
In [1]: import numpy

In [2]: masked = numpy.ma.masked_array([[1, 2, 3, 4, 5]], mask=False)

In [3]: masked[:] = numpy.fliplr(masked.copy())

In [4]: print masked
[[5 4 3 2 1]]

In [5]: masked[:] = numpy.fliplr(masked)

In [6]: print masked
[[1 2 3 2 1]]


Specs:
======
Numpy 1.1.0
Python 2.5.1
OS X Leopard 10.5.3




More information about the NumPy-Discussion mailing list