tags:

views:

58

answers:

4

this:

 numpy.histogram([1,3,2,3,1,1,1,1,2,3,2,5,6,6],bins=numpy.arange(0,7,1))

yields:

(array([0, 5, 3, 3, 0, 3]), array([0, 1, 2, 3, 4, 5, 6]))

why does it count three 6's? there are only 2!

+1  A: 

It looks like it's lumping the 5's and 6's together - maybe the last bin is 5 to 6, inclusive?


Edit: Looking at the docs, I'm guessing that 6 is the rightmost edge, so values between five and six are in that final bin.

thegrinner
+2  A: 

There is one 5 and two 6's in the last bin. Quoting the doc "All but the last (righthand-most) bin is half-open", so the last bin includes the 2 6's.

deinst
+1  A: 

I believe this is related to the semantics of the first and last bins being underflow and overflow. Your total bucket count is correct.

Noah Watkins
+2  A: 

because bins defines the bin edges you need to add one more bin

numpy.histogram([1,3,2,3,1,1,1,1,2,3,2,5,6,6],bins=numpy.arange(0,8,1))
gnibbler