Handle invalid and missing data safely with masked arrays in np.ma.
The `numpy.ma` module provides masked arrays where invalid or corrupted data points are hidden beneath a boolean mask without discarding them from memory.
A masked array is placing opaque sticky tape over erroneous cells in a spreadsheet. Calculations automatically treat taped cells as invisible.
`ma.masked_where(condition, arr)` hides values satisfying a condition. `ma.masked_invalid(arr)` automatically masks NaNs and Infs.
m = ma.masked_where(arr < 0, arr)arr.mean() # Normal array will include the -999 error sentinel!ma.masked_equal(arr, -999).mean() # Correctly ignores sentinelSentinel values like `-999` ruin standard statistics unless masked with `np.ma`.
Solve the objective below using NumPy vectorized syntax
Create `arr = np.array([10, -999, 30])`, mask `-999` with `ma.masked_equal(arr, -999)`, and print its mean.
20.0