Possible Duplicate:
NumPy: calculate averages with NaNs removed
I have several identically-shaped numpy arrays. I want to take their pointwise average with a small twist: a np.nan
value should be ignored in the averaging. In other words, average(np.array([1,2,3]), np.array([5,np.nan,7]), np.array([np.nan, 4, 2])
should equal np.array([3,3,4])
.
Of course, I can do that by iterating through the elements within each numpy array, but I was hoping to avoid it. Is there a better way to implement this function?
(Python 3, but I doubt it matters.)