[Numpy-discussion] numpy.average(fooArray, axis=0): dropping nans from calculation

Sven Schreiber svetosch at gmx.net
Fri Jul 14 02:25:49 CDT 2006

Webb Sprague schrieb:
> Could someone recommend a way to average an array along the columns
> without propagating the nans and without turning them into some weird
> number which bias the result?  I guess I can just keep using an
> indexing array for fooArray, but if there is somehting more graceful,
> I would love to know.

You could take advantage of the nan-related functions:

>>> help(numpy.nansum)
Help on function nansum in module numpy.lib.function_base:

nansum(a, axis=-1)
    Sum the array over the given axis, treating NaNs as 0.

> Boy missing data is a pain in the neck...

Btw, do you know what is treated as NaN in numpy when getting the data
from some external source (file, python list etc.), apart from None? I
asked that on this list but it apparently went unnoticed.


More information about the Numpy-discussion mailing list