How can I calculate matrix mean values along a matrix, but to remove nan values from calculation? (For R people, think na.rm = TRUE).
nan
na.rm = TRUE
Here
From numpy 1.8 (released 2013-10-30) onwards, nanmean does precisely what you need:
>>> import numpy as np >>> np.nanmean(np.array([1.5, 3.5, np.nan])) 2.5