Mask an array where invalid values occur (NaNs or infs). This function is a shortcut to ``masked_where``, with `condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved. Only applies to arrays with a dtype where NaNs or infs make sense (i.e. floating point types), but
(a, copy=True)
| 2330 | |
| 2331 | |
| 2332 | def masked_invalid(a, copy=True): |
| 2333 | """ |
| 2334 | Mask an array where invalid values occur (NaNs or infs). |
| 2335 | |
| 2336 | This function is a shortcut to ``masked_where``, with |
| 2337 | `condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved. |
| 2338 | Only applies to arrays with a dtype where NaNs or infs make sense |
| 2339 | (i.e. floating point types), but accepts any array_like object. |
| 2340 | |
| 2341 | See Also |
| 2342 | -------- |
| 2343 | masked_where : Mask where a condition is met. |
| 2344 | |
| 2345 | Examples |
| 2346 | -------- |
| 2347 | >>> import numpy.ma as ma |
| 2348 | >>> a = np.arange(5, dtype=float) |
| 2349 | >>> a[2] = np.NaN |
| 2350 | >>> a[3] = np.PINF |
| 2351 | >>> a |
| 2352 | array([ 0., 1., nan, inf, 4.]) |
| 2353 | >>> ma.masked_invalid(a) |
| 2354 | masked_array(data=[0.0, 1.0, --, --, 4.0], |
| 2355 | mask=[False, False, True, True, False], |
| 2356 | fill_value=1e+20) |
| 2357 | |
| 2358 | """ |
| 2359 | a = np.array(a, copy=False, subok=True) |
| 2360 | res = masked_where(~(np.isfinite(a)), a, copy=copy) |
| 2361 | # masked_invalid previously never returned nomask as a mask and doing so |
| 2362 | # threw off matplotlib (gh-22842). So use shrink=False: |
| 2363 | if res._mask is nomask: |
| 2364 | res._mask = make_mask_none(res.shape, res.dtype) |
| 2365 | return res |
| 2366 | |
| 2367 | ############################################################################### |
| 2368 | # Printing options # |
nothing calls this directly
no test coverage detected