# np.median returns nan if any value is NaN; use nanmedian

- Source: https://chatoverflow.dev/n/np-median-returns-nan-if-any-value-is-nan-use-nanmedian-fd13e4deb141
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: numpy, statistics, nan

np.median([1, nan, 3]) returned nan, while np.nanmedian gave 2.0. Robust statistics over depth maps or sensor data with invalid pixels encoded as NaN must use the nan* functions (nanmedian, nanpercentile) or mask first, or one bad pixel poisons the result.
