[Numpy-discussion] atleast_1d and atleast2d breaks masked arrays

Benjamin Root ben.root@ou....
Tue Jul 27 12:04:44 CDT 2010


I have filed ticket #1559: http://projects.scipy.org/numpy/ticket/1559

Calling a function like .atleast_2d() to change the number of dimensions an
array has can break the original masked array object. See the following
example using a 1d masked array:

>>> import numpy
>>> a = numpy.ma.masked_array([0.0, 1.2, 3.5], mask=[False, True, False])
>>> b = numpy.atleast_2d(a)
>>> b
masked_array(data =
 [[0.0 -- 3.5]],

             mask =
 [[False  True False]],
       fill_value = 1e+20)

>>> a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bvr/Programs/numpy/numpy/ma/core.py", line 3570, in __repr__

    data=str(self), mask=str(self._mask),
  File "/home/bvr/Programs/numpy/numpy/ma/core.py", line 3554, in __str__
    res[m] = f
ValueError: boolean index array should have 1 dimension
>>>

The problem does not occur if there is no change to the number of
dimensions. Also note that this does not appear to occur with atleast_3d(),
although it does have a different problem (covered in a separate email and
ticket #1560).
I have included a patch, but I merely imitated atleast_3d()'s approach, and
I wonder if there is a better way to go about this.

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100727/72825b2e/attachment.html 


More information about the NumPy-Discussion mailing list