[Numpy-discussion] question on NumPy NaN

Anne Archibald peridot.faceted@gmail....
Tue May 20 11:11:38 CDT 2008


2008/5/20 Vasileios Gkinis <v.gkinis@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