np.tile modifies the mask of the inputted masked array
See original GitHub issueHere 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
Issue Analytics
- State:
- Created 11 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
The numpy.ma module — NumPy v1.24 Manual
A masked array is the combination of a standard numpy.ndarray and a mask. A mask is either ... Convert the input to a...
Read more >Python/Numpy: Using np.tile to tile 2D array of boolean mask ...
You can use: x = np.tile(maskArr, (3, 1, 1)) print(x). Prints: [[[False True False True] [False True True True] [ True True False...
Read more >Masking and padding with Keras | TensorFlow Core
Masking is a way to tell sequence-processing layers that certain timesteps in an input are missing, and thus should be skipped when ...
Read more >Indexing - | notebook.community
We can also index masks: If the index mask is an Numpy array of with data type bool , then an element is...
Read more >Masked array operations — NumPy v1.9 Manual
Determine whether input has masked values. ma.is_mask(m), Return True if m is a valid, standard mask. ma.MaskedArray.data ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the note @cmarmo. Agree, seems this has been fixed years ago! (in gh-10314)
Hello, I have run the snippet of code in the description and I am under the impression that this issue can be closed?
Thanks for listening.