Detect and handle np.nan using isnan(), nanmean(), nanmax(), and nan_to_num().
`np.nan` represents missing or undefined floating-point values. Standard functions propagate NaN (`1 + nan = nan`), while `nan*` functions ignore missing entries.
A `NaN` is a blank page in a ledger. Standard `sum()` panics and returns NaN. `np.nansum()` skips the blank page and adds up all the valid numbers.
By IEEE 754 floating-point standard, `np.nan == np.nan` evaluates to `False`. You must ALWAYS use `np.isnan(arr)` to detect NaNs.
mask = np.isnan(arr); avg = np.nanmean(arr)mask = (arr == np.nan) # ALWAYS returns all False!mask = np.isnan(arr)NaN is never equal to anything, including itself. `== np.nan` will fail 100% of the time.
Solve the objective below using NumPy vectorized syntax
Create `arr = np.array([10.0, np.nan, 20.0])`, calculate its mean ignoring NaNs using `np.nanmean(arr)`, and print.
15.0