MCPcopy
hub / github.com/numpy/numpy / masked_where

Function masked_where

numpy/ma/core.py:1885–2005  ·  view source on GitHub ↗

Mask an array where a condition is met. 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

(condition, a, copy=True)

Source from the content-addressed store, hash-verified

1883###############################################################################
1884
1885def masked_where(condition, a, copy=True):
1886 """
1887 Mask an array where a condition is met.
1888
1889 Return `a` as an array masked where `condition` is True.
1890 Any masked values of `a` or `condition` are also masked in the output.
1891
1892 Parameters
1893 ----------
1894 condition : array_like
1895 Masking condition. When `condition` tests floating point values for
1896 equality, consider using ``masked_values`` instead.
1897 a : array_like
1898 Array to mask.
1899 copy : bool
1900 If True (default) make a copy of `a` in the result. If False modify
1901 `a` in place and return a view.
1902
1903 Returns
1904 -------
1905 result : MaskedArray
1906 The result of masking `a` where `condition` is True.
1907
1908 See Also
1909 --------
1910 masked_values : Mask using floating point equality.
1911 masked_equal : Mask where equal to a given value.
1912 masked_not_equal : Mask where *not* equal to a given value.
1913 masked_less_equal : Mask where less than or equal to a given value.
1914 masked_greater_equal : Mask where greater than or equal to a given value.
1915 masked_less : Mask where less than a given value.
1916 masked_greater : Mask where greater than a given value.
1917 masked_inside : Mask inside a given interval.
1918 masked_outside : Mask outside a given interval.
1919 masked_invalid : Mask invalid values (NaNs or infs).
1920
1921 Examples
1922 --------
1923 >>> import numpy as np
1924 >>> import numpy.ma as ma
1925 >>> a = np.arange(4)
1926 >>> a
1927 array([0, 1, 2, 3])
1928 >>> ma.masked_where(a <= 2, a)
1929 masked_array(data=[--, --, --, 3],
1930 mask=[ True, True, True, False],
1931 fill_value=999999)
1932
1933 Mask array `b` conditional on `a`.
1934
1935 >>> b = ['a', 'b', 'c', 'd']
1936 >>> ma.masked_where(a == 2, b)
1937 masked_array(data=['a', 'b', --, 'd'],
1938 mask=[False, False, True, False],
1939 fill_value='N/A',
1940 dtype='<U1')
1941
1942 Effect of the `copy` argument.

Callers 15

test_mem_masked_whereMethod · 0.90
test_testOddFeaturesMethod · 0.90
test_minmaxMethod · 0.90
test_oddfeatures_1Method · 0.90
test_minmaxMethod · 0.90
masked_greaterFunction · 0.85
masked_greater_equalFunction · 0.85
masked_lessFunction · 0.85

Calls 5

make_maskFunction · 0.85
mask_orFunction · 0.85
_shrink_maskFunction · 0.85
getmaskFunction · 0.85
viewMethod · 0.45

Tested by 9

test_mem_masked_whereMethod · 0.72
test_testOddFeaturesMethod · 0.72
test_minmaxMethod · 0.72
test_oddfeatures_1Method · 0.72
test_minmaxMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…