bundles / numpy latest / numpy / ma / core / masked_where
function
numpy.ma.core:masked_where
source: build-install/usr/lib/python3.14/site-packages/numpy/ma/core.py :1874
Signature
def masked_where ( condition , a , copy = True ) Summary
Mask an array where a condition is met.
Extended Summary
Return a as an array masked where condition is True. Any masked values of a or condition are also masked in the output.
Parameters
condition: array_likeMasking condition. When
conditiontests floating point values for equality, consider usingmasked_valuesinstead.a: array_likeArray to mask.
copy: boolIf True (default) make a copy of
ain the result. If False modifyain place and return a view.
Returns
result: MaskedArrayThe result of masking
awhereconditionis True.
Examples
import numpy as np import numpy.ma as ma a = np.arange(4) a ma.masked_where(a <= 2, a)Mask array `b` conditional on `a`.
b = ['a', 'b', 'c', 'd'] ma.masked_where(a == 2, b)Effect of the `copy` argument.
c = ma.masked_where(a <= 2, a) c c[0] = 99 c a c = ma.masked_where(a <= 2, a, copy=False) c[0] = 99 c aWhen `condition` or `a` contain masked values.
a = np.arange(4) a = ma.masked_where(a == 2, a) a b = np.arange(4) b = ma.masked_where(b == 0, b) b ma.masked_where(a == 3, b)
See also
- masked_equal
Mask where equal to a given value.
- masked_greater
Mask where greater than a given value.
- masked_greater_equal
Mask where greater than or equal to a given value.
- masked_inside
Mask inside a given interval.
- masked_invalid
Mask invalid values (NaNs or infs).
- masked_less
Mask where less than a given value.
- masked_less_equal
Mask where less than or equal to a given value.
- masked_not_equal
Mask where not equal to a given value.
- masked_outside
Mask outside a given interval.
- masked_values
Mask using floating point equality.
Aliases
-
numpy.ma.masked_where