[Numpy-discussion] question on NumPy NaN

Anne Archibald peridot.faceted at gmail.com
Tue May 20 12:11:38 EDT 2008


2008/5/20 Vasileios Gkinis <v.gkinis at rug.nl>:

> 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



More information about the NumPy-Discussion mailing list