Skip to content

np.tile modifies the mask of the inputted masked array #3140

Closed
@tjanez

Description

@tjanez

Here is an example of the problem:

>>> import numpy as np
>>> import numpy.ma as ma
>>> A = ma.masked_array(np.array([1., 2.]), mask=np.array([False, False]))
>>> A
masked_array(data = [1.0 2.0],
             mask = [False False],
       fill_value = 1e+20)

>>> B = np.tile(A, (2, 1))
>>> A
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/numpy/ma/core.py", line 3553, in __repr__
    data=str(self), mask=str(self._mask),
  File "/usr/lib64/python2.7/site-packages/numpy/ma/core.py", line 3537, in __str__
    res[m] = f
ValueError: boolean index array should have 1 dimension
>>> A._data
array([ 1.,  2.])
>>> A._mask
array([[False, False]], dtype=bool)

The issue is that the call to np.tile changed A._mask from array([False, False], dtype=bool) to array([[False, False]], dtype=bool), which made the __repr___() function return the error.

Digging deeper, I found that the issue is with the call _nx.array(A,copy=False,subok=True,ndmin=d) in the tile function.
Before this call, A has the correct _mask and after this call, A's _mask changes.

Does anyone have any ideas how to fix this?

This is on Fedora-rawhide with:
python-2.7.3-34.fc19.x86_64
numpy-1.7.0-1.fc19.x86_64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions