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
How about using Pandas to do this:
import numpy as np import pandas as pd dat = np.array([[1, 2, 3], [4, 5, np.nan], [np.nan, 6, np.nan], [np.nan, np.nan, np.nan]]) print dat print dat.mean(1) df = pd.DataFrame(dat) print df.mean(axis=1)
Gives:
0 2.0 1 4.5 2 6.0 3 NaN