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)
| 2325 | |
| 2326 | |
| 2327 | def masked_values(x, value, rtol=1e-5, atol=1e-8, copy=True, shrink=True): |
| 2328 | """ |
| 2329 | Mask using floating point equality. |
| 2330 | |
| 2331 | Return a MaskedArray, masked where the data in array `x` are approximately |
| 2332 | equal to `value`, determined using `isclose`. The default tolerances for |
| 2333 | `masked_values` are the same as those for `isclose`. |
| 2334 | |
| 2335 | For integer types, exact equality is used, in the same way as |
| 2336 | `masked_equal`. |
| 2337 | |
| 2338 | The fill_value is set to `value` and the mask is set to ``nomask`` if |
| 2339 | possible. |
| 2340 | |
| 2341 | Parameters |
| 2342 | ---------- |
| 2343 | x : array_like |
| 2344 | Array to mask. |
| 2345 | value : float |
| 2346 | Masking value. |
| 2347 | rtol, atol : float, optional |
| 2348 | Tolerance parameters passed on to `isclose` |
| 2349 | copy : bool, optional |
| 2350 | Whether to return a copy of `x`. |
| 2351 | shrink : bool, optional |
| 2352 | Whether to collapse a mask full of False to ``nomask``. |
| 2353 | |
| 2354 | Returns |
| 2355 | ------- |
| 2356 | result : MaskedArray |
| 2357 | The result of masking `x` where approximately equal to `value`. |
| 2358 | |
| 2359 | See Also |
| 2360 | -------- |
| 2361 | masked_where : Mask where a condition is met. |
| 2362 | masked_equal : Mask where equal to a given value (integers). |
| 2363 | |
| 2364 | Examples |
| 2365 | -------- |
| 2366 | >>> import numpy as np |
| 2367 | >>> import numpy.ma as ma |
| 2368 | >>> x = np.array([1, 1.1, 2, 1.1, 3]) |
| 2369 | >>> ma.masked_values(x, 1.1) |
| 2370 | masked_array(data=[1.0, --, 2.0, --, 3.0], |
| 2371 | mask=[False, True, False, True, False], |
| 2372 | fill_value=1.1) |
| 2373 | |
| 2374 | Note that `mask` is set to ``nomask`` if possible. |
| 2375 | |
| 2376 | >>> ma.masked_values(x, 2.1) |
| 2377 | masked_array(data=[1. , 1.1, 2. , 1.1, 3. ], |
| 2378 | mask=False, |
| 2379 | fill_value=2.1) |
| 2380 | |
| 2381 | Unlike `masked_equal`, `masked_values` can perform approximate equalities. |
| 2382 | |
| 2383 | >>> ma.masked_values(x, 2.1, atol=1e-1) |
| 2384 | masked_array(data=[1.0, 1.1, --, 1.1, 3.0], |
searching dependent graphs…