Masked arrays are NumPy arrays that may have missing or invalid entries. The `numpy.ma` module provides a nearly work-alike replacement for NumPy that supports data arrays with masks.
Questions tagged [masked-array]
151 questions
0
votes
1 answer
Create masked array from list containing ma.masked
If I have a (possibly multidimensional) Python list where each element is one of True, False, or ma.masked, what's the idiomatic way of turning this into a masked numpy array of bool?
Example:
>>> print(somefunc([[True, ma.masked], [False,…

Kyuuhachi
- 651
- 6
- 15
0
votes
0 answers
How to binarize results for a masked array?
I'm looking to assess where temperatures in Canada will be between 15 and 35 °C in Canada in 2030 using a projection model. I created a masked array that fits within this set of parameters, and has the same latitude and longitude axes as the…

sienna22
- 21
- 3
0
votes
2 answers
ValueError could not broadcast where mask from shape (1) into shape ()
There are a lot of questions related to ValueErrors where input arrays of different shape cannot be broadcast here at SO. But there are none are related to masks:
ValueError could not broadcast where mask from shape (1) into shape ()
What I'm doing…

hintze
- 544
- 2
- 13
0
votes
1 answer
Why does np.ma.array take an inverted mask?
I have some array
a = np.array([1, 2, 3])
and some mask
mask = np.ones(a.shape, dtype=bool)
and can do
np.testing.assert_almost_equal(a[mask], a) # True
However,
np.ma.array(a, mask)
is equivalent to…

Gulzar
- 23,452
- 27
- 113
- 201
0
votes
1 answer
How to keep the same units from my precipitation data when using masked_array?
I am attempting to create a precipitation map with one nc file, similar to a NWS example that I found here.
In my case, though, my precipitation data is already in mm. How do I keep the same units? I did read the following,
Create a…

Jocelyn
- 3
- 1
0
votes
2 answers
Find where is masked in Numpy
I want to get the position in a masked array.
Like this
wt[chl > 10] = 3
wt[(chl < 10) & (chl > 5)] = 2
wt[(chl < 5)] = 1
wt[(chl is masked )]=0
wt and chl is in the same shape. I want to give wt value according to the value and attribute(masked or…

lifeodyssey
- 15
- 6
0
votes
1 answer
How to create a numpy masked array using lower dim array as a mask?
Assume
a = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
]
mask = [1, 0, 1]
I want
a[mask] == [
[1, 2, 3],
[False, False, False],
[7, 8, 9],
]
or equivalent.
Meaning, I want to access a…

Gulzar
- 23,452
- 27
- 113
- 201
0
votes
0 answers
How to obtain a subset of a range masked by a boolean NumPy array?
I need to do integer array indexing of a continuous integer range [0, n) which has values that have to be always ignored.
The ignored values should not appear in the result.
And there is a stand-alone NumPy boolean array of length n (i.e., a mask)…

Alexander Pozdneev
- 1,289
- 1
- 13
- 31
0
votes
1 answer
How to make np.ma.argmin return None if every element is masked?
Motivation: in a list of numeric values I try to find the index of the smallest value - with the side condition, that the value has to below a certain treshold. Here is an example where everything works as expected
import numpy as np
a =…

Qaswed
- 3,649
- 7
- 27
- 47
0
votes
1 answer
Want to make an array with zeros when data is masked and ones when data is not masked
I have netcdf data that is masked. The data is in (time, latitude, longitude). I would like to make an array with the same size as the original data but with zeros when the data is masked and with ones where it is not masked. So fare I have tried to…

Idalh
- 31
- 3
0
votes
2 answers
Masked `np.nan` in the `np.ma.array` problem in jupyter
Let's run in the Anaconda Jupyter the Python3 NumPy code:
y = np.ma.array(np.matrix([[np.nan, 2.0]]), mask=[0, 1])
m = (y < 0.01)
and we have the warning: /.../anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:2: RuntimeWarning: invalid…

zeta0
- 101
- 3
0
votes
1 answer
Masked values in numpy digitize
I want that numpy digitize ignores some values in my array. To achieve this I replaced the unwanted values by NaN and masked the NaN values:
import numpy as np
A = np.ma.array(A, mask=np.isnan(A))
Nonetheless np.digitize throws the masked values…

clearseplex
- 679
- 1
- 7
- 22
0
votes
3 answers
effectively check if data are masked array and all data are masked True
I have arrays that are simple numpy.ndarrays while other times the same variable may be a masked array. I'd like to figure out the most effective way to check if there are data in the array and that ALL are not masked
I've got the below to…

SBFRF
- 167
- 2
- 16
0
votes
1 answer
Delete slice from a 3D numpy.MaskedArray
I have a 3D numpy.MaskedArray and I want to delete the 3rd slice. If I was a numpy.array I could just use the numpy.delete function, e.g. np.delete(arr, obj=3, axis=0). However, this function is not available for np.MaskedArrays. How can I do this…

pan
- 101
- 4
0
votes
0 answers
Numpy: Unable to get the correct data from MaskedArray
I wasn't expecting the following behaviour when extracting the data from a a masked array.
I have the following MaskedArray:
import numpy as np
data = [[7374.0, 10244.0, 7386.0, -0.16211003970504823],
[7433.0, 12013.0, 7569.0,…

AguaraGuazu
- 23
- 3