You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / ma / core / masked_where

function

numpy.ma.core:masked_where

source: /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_like

Masking condition. When 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 condition is 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
a
When `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