numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
masked_where(condition, a, copy=True)

Return a as an array masked where :None:None:`condition` is True. Any masked values of a or :None:None:`condition` are also masked in the output.

Parameters

condition : array_like

Masking condition. When :None:None:`condition` tests floating point values for equality, consider using masked_values instead.

a : array_like

Array to mask.

copy : bool

If True (default) make a copy of a in the result. If False modify a in place and return a view.

Returns

result : MaskedArray

The result of masking a where :None:None:`condition` is True.

Mask an array where a condition is met.

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 :None:None:`not` equal to a given value.

masked_outside

Mask outside a given interval.

masked_values

Mask using floating point equality.

Examples

This example is valid syntax, but we were not able to check execution
>>> import numpy.ma as ma
... a = np.arange(4)
... a array([0, 1, 2, 3])
This example is valid syntax, but we were not able to check execution
>>> ma.masked_where(a <= 2, a)
masked_array(data=[--, --, --, 3],
             mask=[ True,  True,  True, False],
       fill_value=999999)

Mask array :None:None:`b` conditional on a.

This example is valid syntax, but we were not able to check execution
>>> 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 copy argument.

This example is valid syntax, but we were not able to check execution
>>> c = ma.masked_where(a <= 2, a)
... c masked_array(data=[--, --, --, 3], mask=[ True, True, True, False], fill_value=999999)
This example is valid syntax, but we were not able to check execution
>>> c[0] = 99
... c masked_array(data=[99, --, --, 3], mask=[False, True, True, False], fill_value=999999)
This example is valid syntax, but we were not able to check execution
>>> a
array([0, 1, 2, 3])
This example is valid syntax, but we were not able to check execution
>>> 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)
This example is valid syntax, but we were not able to check execution
>>> a
array([99,  1,  2,  3])

When :None:None:`condition` or a contain masked values.

This example is valid syntax, but we were not able to check execution
>>> 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)
This example is valid syntax, but we were not able to check execution
>>> 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)
This example is valid syntax, but we were not able to check execution
>>> ma.masked_where(a == 3, b)
masked_array(data=[--, 1, --, --],
             mask=[ True, False,  True,  True],
       fill_value=999999)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.ma.extras.mask_rows numpy.ma.extras.mask_cols numpy.ma.core.masked_less_equal numpy.ma.core.masked_greater dask.array.ma.masked_where dask.array.ma.set_fill_value numpy.ma.core.masked_values numpy.ma.core.masked_inside numpy.ma.core.masked_object numpy.ma.core.masked_equal numpy.ma.core.masked_greater_equal numpy.ma.core.masked_invalid numpy.ma.core.masked_less numpy.ma.core.masked_not_equal numpy.ma.core.mask_rowcols numpy.ma.core.masked_outside

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/ma/core.py#1821
type: <class 'function'>
Commit: