[Numpy-tickets] [NumPy] #241: maximum and nan / identity for maximum

NumPy numpy-tickets at scipy.net
Mon Oct 23 19:18:06 CDT 2006


#241: maximum and nan / identity for maximum
-----------------------------+----------------------------------------------
 Reporter:  martin_wiechert  |        Owner:  somebody   
     Type:  enhancement      |       Status:  new        
 Priority:  normal           |    Milestone:  1.0 Release
Component:  numpy.core       |      Version:  devel      
 Severity:  normal           |   Resolution:             
 Keywords:                   |  
-----------------------------+----------------------------------------------
Comment (by peridot):

 Replying to [comment:2 oliphant]:
 > NaN's are a peculiar creature.  Their behavior on comparison can be
 confusing but it is consistent.  Numpy just inherits the way the platform
 treats nans.  It doesn't try to do anything special with them by default
 as that would slow down all code (even code where the user knows nans are
 not going to show up).

 Unfortunately, the right behaviour for maximum would be to return a nan if
 any element is a nan. The current behaviour comes from the fact that nan
 returns false for all comparisons, so in fact what happens now is that the
 nan is ignored unless it's in the first place, in which case the result is
 nan. It would be easy to check for this.
 {{{
 In [9]: minimum.reduce(array([1,2,3,nan,2]))
 Out[9]: 1.0

 In [10]: minimum.reduce(array([nan,1,2,3,2]))
 Out[10]: nan

 In [11]: minimum.reduce(array([inf,nan,1,2,3,2]))
 Out[11]: 1.0
 }}}
 In fact, a fix for this would be to use -inf as the initial (identity)
 value; another would be to set nans to raise an exception, which could
 then be trapped and handled specially before returning the exception state
 to normal.

 It'd be nice to avoid secret disappearing nans, but if that's infeasible,
 I think removing the special behaviour when nan is first would help.

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/241#comment:3>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list