[NumPy-Tickets] [NumPy] #1123: nansum for empty or all nan arrays is not zero

NumPy Trac numpy-tickets@scipy....
Tue Jan 18 01:12:41 CST 2011

#1123: nansum for empty or all nan arrays is not zero
 Reporter:  josefpktd  |       Owner:  charris     
     Type:  defect     |      Status:  needs_review
 Priority:  normal     |   Milestone:  2.0.0       
Component:  numpy.lib  |     Version:              
 Keywords:             |  
Changes (by markhmoulton@…):

 * cc: markhmoulton@… (added)


 It is a mistake to define a sum of NaNs to equal zero.

 Example: Ten sensors return readings on a scale of 0 to 1000, the sum of
 each sensor's readings typically having a mean of 500.  Half the sensors
 in this case malfunction and return missing data.  If a sum of NaNs is
 defined to equal zero, the array of sensor sums looks something like
 [500,650,350,525,725,0,0,0,0,0].  The resulting average is 275 instead of

 This simple error is deadly and far too frequent.  We shouldn't encourage
 it.  By Numpy assigning the same character to all missing or invalid
 values, it allows me to use only one technique (e.g., NaN masks) to catch
 and remove them.  If some invalid values are coded as NaN and others as
 zero, I have to second-guess the programmers and do a separate check to
 look for zeros and their antecedents.  Ugh.

Ticket URL: <http://projects.scipy.org/numpy/ticket/1123#comment:14>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list