[SciPy-User] numpy.nansum bug?

Matthew Brett matthew.brett@gmail....
Tue Sep 21 20:46:17 CDT 2010


Hi,

On Tue, Sep 21, 2010 at 6:41 PM, Benjamin Root <ben.root@ou.edu> wrote:
> On Tue, Sep 21, 2010 at 4:49 PM, Jeremy Sanders <jeremy@jeremysanders.net>
> wrote:
>>
>> I've hit this problem with numpy (1.3.0 on x86-64).
>>
>> In [12]: a = numpy.array([numpy.nan])
>>
>> In [13]: numpy.nansum(a)
>> Out[13]: nan
>>
>> I assume that this is a bug? It's pretty nasty if you assume that nansum
>> always returns a non nan.
>>
>> This is also pretty weird:
>> In [14]: numpy.nansum([])
>> Out[14]: nan
>>
>> Jeremy
>>
>>
>
> I am not certain if this is a bug or not, but I would like to point out the
> documentation:
>
> "Return the sum of array elements over a given axis treating Not a Numbers
> (NaNs) as zero."
>
> So, either there is a bug, or the documentation needs to be clearer.

Right.  And given that:

In [2]: np.sum([])
Out[2]: 0.0

I'd vote for both to be bugs, that is:

np.nansum([np.nan]) should return 0 and
np.nansum([]) should return 0

See you,

Matthew


More information about the SciPy-User mailing list