[SciPy-user] calculate average by excluding NaN value in Array
David Cournapeau
david@ar.media.kyoto-u.ac...
Mon Mar 30 05:44:05 CDT 2009
David Cournapeau wrote:
> Ch B Komaki wrote:
>
>> Dear Sirs/Madams
>> I wanna calculate average of some lists, but having Nan value makes
>> difficult to calculate average of data , I wanna exclude the position
>> has NaN.It should calculate average of the others instead ;
>> for example;
>>
>>
>
> nanmean should do what you want,
>
>
which is in scipy.stats:
import numpy as np
from scipy.stats import nanmean
nanmean(np.array([1, 2, 3, np.nan])) # should return 2.
David
More information about the SciPy-user
mailing list