[Numpy-discussion] copying in nanXXX

Damian Eads eads at soe.ucsc.edu
Sun Jun 29 20:24:43 EDT 2008


Hi there,

I'm using nansum for some code and noticed it does a bit of copying. 
Specifically, the nanxxx functions copy the input array, create an isnan 
boolean mask, set the nan values to make them insignificant (nansum: 0, 
nanmin: inf, or nanmax: -inf), and then call xxx to compute the statistic.

def nansum(a, axis=None):
     """Sum the array over the given axis, treating NaNs as 0.
     """
     y = array(a,subok=True)
     if not issubclass(y.dtype.type, _nx.integer):
         y[isnan(a)] = 0
     return y.sum(axis)

Unless someone has already done this, I will offer to write C versions 
of these functions. Does anyone else think this is useful?

Cheers,

Damian



More information about the NumPy-Discussion mailing list