On this page
numpy.ma.masked_where
numpy.ma.masked_where(condition, a, copy=True)[source]-
Mask an array where a condition is met.
Return
aas an array masked whereconditionis True. Any masked values ofaorconditionare also masked in the output.Parameters: -
condition : array_like -
Masking condition. When
conditiontests floating point values for equality, consider usingmasked_valuesinstead. -
a : array_like -
Array to mask.
-
copy : bool -
If True (default) make a copy of
ain the result. If False modifyain place and return a view.
Returns: -
result : MaskedArray -
The result of masking
awhereconditionis True.
See also
masked_values- Mask using floating point equality.
masked_equal- Mask where equal to a given value.
masked_not_equal-
Mask where
notequal to a given value. masked_less_equal- Mask where less than or equal to a given value.
masked_greater_equal- Mask where greater than or equal to a given value.
masked_less- Mask where less than a given value.
masked_greater- Mask where greater than a given value.
masked_inside- Mask inside a given interval.
masked_outside- Mask outside a given interval.
masked_invalid- Mask invalid values (NaNs or infs).
Examples
>>> import numpy.ma as ma >>> a = np.arange(4) >>> a array([0, 1, 2, 3]) >>> ma.masked_where(a <= 2, a) masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999)Mask array
bconditional ona.>>> b = ['a', 'b', 'c', 'd'] >>> ma.masked_where(a == 2, b) masked_array(data=['a', 'b', --, 'd'], mask=[False, False, True, False], fill_value='N/A', dtype='<U1')Effect of the
copyargument.>>> c = ma.masked_where(a <= 2, a) >>> c masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999) >>> c[0] = 99 >>> c masked_array(data=[99, --, --, 3], mask=[False, True, True, False], fill_value=999999) >>> a array([0, 1, 2, 3]) >>> c = ma.masked_where(a <= 2, a, copy=False) >>> c[0] = 99 >>> c masked_array(data=[99, --, --, 3], mask=[False, True, True, False], fill_value=999999) >>> a array([99, 1, 2, 3])When
conditionoracontain masked values.>>> a = np.arange(4) >>> a = ma.masked_where(a == 2, a) >>> a masked_array(data=[0, 1, --, 3], mask=[False, False, True, False], fill_value=999999) >>> b = np.arange(4) >>> b = ma.masked_where(b == 0, b) >>> b masked_array(data=[--, 1, 2, 3], mask=[ True, False, False, False], fill_value=999999) >>> ma.masked_where(a == 3, b) masked_array(data=[--, 1, --, --], mask=[ True, False, True, True], fill_value=999999) -
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
https://docs.scipy.org/doc/numpy-1.17.0/reference/generated/numpy.ma.masked_where.html