Srivatsan
Srivatsan

Reputation: 9363

Python histogram bins

I have this histogram:

    hist
(array([49, 33, 21, 11, 10,  9,  0,  0,  0,  2]), array([ 0.        ,  0.26274885,  0.52549769,  0.78824654,  1.05099538,
        1.31374423,  1.57649308,  1.83924192,  2.10199077,  2.36473962,
        2.62748846]))

which has 10 bins and the number of counts in each bin. I would like to extract the first array, i.e the number counts in each bin (array([49, 33, 21, 11, 10, 9, 0, 0, 0, 2]) to use for another calculation.

Is this possible?

Upvotes: 1

Views: 234

Answers (1)

Fredrik Pihl
Fredrik Pihl

Reputation: 45634

use hist[0]

Read more in the official tutorial

http://docs.python.org/2.7/tutorial/introduction.html#lists

Like string indices, list indices start at 0, and lists can be sliced, concatenated and so on:

>>> a = ['spam', 'eggs', 100, 1234]
>>>
>>> a[0]
'spam'
>>> a[3]
1234
>>> a[-2]
100
>>> a[1:-1]
['eggs', 100]
>>> a[:2] + ['bacon', 2*2]
['spam', 'eggs', 'bacon', 4]
>>> 3*a[:3] + ['Boo!']
['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boo!']

Upvotes: 3

Related Questions