MCPcopy Create free account
hub / github.com/numpy/numpy / masked_values

Function masked_values

numpy/ma/core.py:2260–2329  ·  view source on GitHub ↗

Mask using floating point equality. Return a MaskedArray, masked where the data in array `x` are approximately equal to `value`, determined using `isclose`. The default tolerances for `masked_values` are the same as those for `isclose`. For integer types, exact equality is use

(x, value, rtol=1e-5, atol=1e-8, copy=True, shrink=True)

Source from the content-addressed store, hash-verified

2258
2259
2260def masked_values(x, value, rtol=1e-5, atol=1e-8, copy=True, shrink=True):
2261 """
2262 Mask using floating point equality.
2263
2264 Return a MaskedArray, masked where the data in array `x` are approximately
2265 equal to `value`, determined using `isclose`. The default tolerances for
2266 `masked_values` are the same as those for `isclose`.
2267
2268 For integer types, exact equality is used, in the same way as
2269 `masked_equal`.
2270
2271 The fill_value is set to `value` and the mask is set to ``nomask`` if
2272 possible.
2273
2274 Parameters
2275 ----------
2276 x : array_like
2277 Array to mask.
2278 value : float
2279 Masking value.
2280 rtol, atol : float, optional
2281 Tolerance parameters passed on to `isclose`
2282 copy : bool, optional
2283 Whether to return a copy of `x`.
2284 shrink : bool, optional
2285 Whether to collapse a mask full of False to ``nomask``.
2286
2287 Returns
2288 -------
2289 result : MaskedArray
2290 The result of masking `x` where approximately equal to `value`.
2291
2292 See Also
2293 --------
2294 masked_where : Mask where a condition is met.
2295 masked_equal : Mask where equal to a given value (integers).
2296
2297 Examples
2298 --------
2299 >>> import numpy.ma as ma
2300 >>> x = np.array([1, 1.1, 2, 1.1, 3])
2301 >>> ma.masked_values(x, 1.1)
2302 masked_array(data=[1.0, --, 2.0, --, 3.0],
2303 mask=[False, True, False, True, False],
2304 fill_value=1.1)
2305
2306 Note that `mask` is set to ``nomask`` if possible.
2307
2308 >>> ma.masked_values(x, 2.1)
2309 masked_array(data=[1. , 1.1, 2. , 1.1, 3. ],
2310 mask=False,
2311 fill_value=2.1)
2312
2313 Unlike `masked_equal`, `masked_values` can perform approximate equalities.
2314
2315 >>> ma.masked_values(x, 2.1, atol=1e-1)
2316 masked_array(data=[1.0, 1.1, --, 1.1, 3.0],
2317 mask=[False, False, True, False, False],

Callers 4

test_matrix_indexingMethod · 0.90
test_testCIMethod · 0.90
test_indexingMethod · 0.90
test_masked_valuesMethod · 0.90

Calls 2

filledFunction · 0.85
shrink_maskMethod · 0.80

Tested by 4

test_matrix_indexingMethod · 0.72
test_testCIMethod · 0.72
test_indexingMethod · 0.72
test_masked_valuesMethod · 0.72