An other possibility is the following:
import numpy
from scipy.stats import nanmean # nanmedian exists too, if you need it
A = numpy.array([5, numpy.nan, numpy.nan, numpy.nan, numpy.nan, 10])
print nanmean(A) # gives 7.5 as expected
i guess this looks more elegant (and readable) than the other solution already given
edit: apparently (@Jaime) reports that this functionality already exists directly in the latest numpy
(1.8) as well, so no need to import scipy.stats
anymore if you have that version of numpy
:
import numpy
A = numpy.array([5, numpy.nan, numpy.nan, numpy.nan, numpy.nan, 10])
print numpy.nanmean(A)
the first solution works also for people who dont have the latest version of numpy
(like me)