[Numpy-discussion] What should be the value of nansum of nan's?
Wed Apr 28 12:56:37 CDT 2010
On Mon, Apr 26, 2010 at 10:03 AM, Charles R Harris
> On Mon, Apr 26, 2010 at 10:55 AM, Charles R Harris
> <firstname.lastname@example.org> wrote:
>> Hi All,
>> We need to make a decision for ticket #1123 regarding what nansum should
>> return when all values are nan. At some earlier point it was zero, but
>> currently it is nan, in fact it is nan whatever the operation is. That is
>> consistent, simple and serves to mark the array or axis as containing all
>> nans. I would like to close the ticket and am a bit inclined to go with the
>> current behaviour although there is an argument to be made for returning 0
>> for the nansum case. Thoughts?
> To add a bit of context, one could argue that the results should be
> consistent with the equivalent operations on empty arrays and always be
> In : nansum()
> Out: nan
> In : sum()
> Out: 0.0
This seems like an obvious one to me. What is the spirit of nansum?
Return the sum of array elements over a given axis treating
Not a Numbers (NaNs) as zero.
Okay. So NaNs in an array are treated as zeros and the sum is
performed as one normally would perform it starting with an initial
sum of zero. So if all values are NaN, then we add nothing to our
original sum and still return 0.
I'm not sure I understand the argument that it should return NaN. It
is counter to the *purpose* of nansum. Also, if one wants to
determine if all values in an array are NaN, isn't there another way?
Let's keep (or make) those distinct operations, as they are definitely
More information about the NumPy-Discussion