I have a numpy array like the following:
x = array([[ 1., 2., 3.],
[ 4., 5., 6.],
[ nan, 8., 9.]])
and I want to calculate the mean of each column. If I use np.mean(x, axis=0)
, then I get nan
as the mean of the first column, and using x[~np.isnan(x)]
to filter out nan
values flattens the array into a 1D array.
I'm required to use an older version of numpy, so I can't use numpy.nanmean
Edit: This comment explains why this isn't a duplicate of the question posted