# question on NumPy NaN Classic List Threaded 5 messages Open this post in threaded view
|

## question on NumPy NaN

-------- Original Message --------
Subject: question on NumPy NaN Tue, 20 May 2008 18:03:00 +0200 Vasileios Gkinis [hidden email] [hidden email]

Hi all,

I have a question concerning nan in NumPy.
Lets say i have an array of sample measurements
a = array((2,4,nan))
in NumPy calculating the mean of the elements in array a looks like:

>>> a = array((2,4,nan))
>>> a
array([  2.,   4.,  NaN])
>>> mean(a)
nan

What if i simply dont want nan to propagate and get something that would look like:

>>> a = array((2,4,nan))
>>> a
array([  2.,   4.,  NaN])
>>> mean(a)
3.

Cheers

Vasilis
--
------------------------------------------------------------

------------------------------------------------------------

Vasileios Gkinis, PhD Student

Centre for Ice and Climate

Niels Bohr Institute

Juliane Maries Vej 30, room 321

DK-2100 Copenhagen

Denmark

Office: +45 35325913

[hidden email]

_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Open this post in threaded view
|

## Re: question on NumPy NaN

 2008/5/20 Vasileios Gkinis <[hidden email]>: > I have a question concerning nan in NumPy. > Lets say i have an array of sample measurements > a = array((2,4,nan)) > in NumPy calculating the mean of the elements in array a looks like: > >>>> a = array((2,4,nan)) >>>> a > array([  2.,   4.,  NaN]) >>>> mean(a) > nan > > What if i simply dont want nan to propagate and get something that would > look like: > >>>> a = array((2,4,nan)) >>>> a > array([  2.,   4.,  NaN]) >>>> mean(a) > 3. For more elaborate handling of missing data, look into "masked arrays", in numpy.ma. They are designed to deal with exactly this sort of thing. Anne _______________________________________________ Numpy-discussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpy-discussion
Open this post in threaded view
|

## Re: question on NumPy NaN

 On Tue, May 20, 2008 at 9:11 AM, Anne Archibald <[hidden email]> wrote: > 2008/5/20 Vasileios Gkinis <[hidden email]>: > >> I have a question concerning nan in NumPy. >> Lets say i have an array of sample measurements >> a = array((2,4,nan)) >> in NumPy calculating the mean of the elements in array a looks like: >> >>>>> a = array((2,4,nan)) >>>>> a >> array([  2.,   4.,  NaN]) >>>>> mean(a) >> nan >> >> What if i simply dont want nan to propagate and get something that would >> look like: >> >>>>> a = array((2,4,nan)) >>>>> a >> array([  2.,   4.,  NaN]) >>>>> mean(a) >> 3. > > For more elaborate handling of missing data, look into "masked > arrays", in numpy.ma. They are designed to deal with exactly this sort > of thing. Or np.nansum(a) / np.isfinite(a).sum() A nanmean would be nice to have in numpy. _______________________________________________ Numpy-discussion mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/numpy-discussion