[SciPy-user] arrays mean & NaN...

David Cournapeau david@ar.media.kyoto-u.ac...
Tue Sep 11 01:09:51 CDT 2007


Wolfgang Kerzendorf wrote:
> It would be a very good idea, I use nan very often and have trouble when 
> computing the mean. I think it would be better to have a switch in the 
> mean function to switch to ignoring nans. Could that be implemented in 
> other funtions like squaresum (ss) as well?
>   
The nanmean, nanmedian and nanstd already exist, but for some reason are 
not exposed at the package module:

from scipy.stats.stats import nanmean, nanmedian, nanstd
import numpy as N
a = N.array([1., 2., N.nan])
N.mean(a) # -> returns Nan
nanmean(a) # -> returns 1.5, treating Nan as a missing value

cheers,

David


More information about the SciPy-user mailing list