# [Numpy-discussion] histogram using decending range -- what do the results mean?

Stuart Brorson sdb@cloud9....
Fri Oct 5 16:32:03 CDT 2007

```Guys --

I'm a little puzzled by a NumPy behavior.  Perhaps the gurus on this

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:

------------------------  <session log>  --------------------

>>> 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])
>>>
--------------------  </session log>  ------------------------

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)?

*  Why should the return histogram have negative elements?

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

Thanks!

Stuart
```