I am summing arrays containing nan
values by using:
for i in range(whatever):
a = *something different at each cycle*
b = np.nansum([b, a],axis=0)
#now calculate the average of b elements avoiding nan counts
(b
and a
being of the same size).
Now, as you can see, this is iterative, adding the elements to create at the end one single sum-array.
At the end, I would like to calculate the average for each of the elements of the final b
array, excluding the nan
elements from the count, of course.
All the other discussions I found only take in account two arrays, and the average of their elements is obtained by using nanmean, but this is not possible here, I think.
Possibly, I could also change the way to sum the elements, if nansum
is not the best way, but this is how I did it until now.
So, is there a simple way to obtain the final average excluding nan
elements from the count?
EDIT: the iteration is made several times, not just one, using a
array (in the example) changing in each cycle. This is why I am not able to use the same solution as in the linked question