[Numpy-tickets] [NumPy] #586: (Retry) Patch to detect max < min in histogram(X, range)

NumPy numpy-tickets@scipy....
Thu Oct 18 23:19:44 CDT 2007


#586: (Retry) Patch to detect max < min in histogram(X, range)
-------------------------+--------------------------------------------------
 Reporter:  brorson      |        Owner:  somebody
     Type:  enhancement  |       Status:  new     
 Priority:  normal       |    Milestone:  1.0.4   
Component:  numpy.lib    |      Version:  none    
 Severity:  normal       |   Resolution:          
 Keywords:               |  
-------------------------+--------------------------------------------------
Comment (by jarrod.millman):

 Robert Kern's response to Stuart Brorson's original email follows:

 > I am working with {{{numpy.histogram}}}.  I have a decent understanding
 of
 > how it works when given an ascending range to bin into.  However, when
 > I give it a '''decending''' range, I can't figure out what the results
 > mean.  Here's an example:
 {{{
 >>> A = numpy.array([1, 2, 3, 4, 5, 6, 5, 4, 5, 4, 3, 2, 1])
 >>> (x, y) = numpy.histogram(A, range=(0, 7))
 >>> x
  array([0, 2, 2, 0, 2, 3, 0, 3, 1, 0])
 >>> (x, y) = numpy.histogram(A, range=(7, 0))
 >>> x
  array([ 0, -1, -3,  0, -3, -2,  0, -2, -2, 13])
 }}}
 > Please set aside the natural response "the user shouldn't bin into
 > a decending range!" since I am trying to figure out what computation
 > {{{NumPy}}} actually does in this case and I don't want a work-around.
 And
 > yes, I have looked at the source.  It's nicely vectorized, so I find
 > the source rather opaque.
 >
 > Therefore, I would appreciate it if if some kind soul could answer a
 > couple of questions:

 > *  What does the return mean for range=(7, 0)?

 Nothing.

 > *  Why should the return histogram have negative elements?

 Because there are subtractions involved that depend on the bins being
 increasing
 which they are not if the given range is incorrect.

 > *  If it truely isn't meaningful, why not catch the case and reject
 > input?  Maybe this is a bug....  ???

 Patches are welcome.

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


More information about the Numpy-tickets mailing list