Skip to content
Justice Tech School

Histograms and Bins

histogram counts values in bins and digitize assigns bin numbers.

Example
a = np.array([1, 2, 2, 3, 3, 3, 4])
counts, edges = np.histogram(a, bins=3)
print(counts, edges.round(2))
print(np.digitize([1.5, 3.5], [0, 2, 4]))

Result

[1 2 4] [1. 2. 3. 4.]
[1 2]

Exercise

Count in bins.

np.(a, bins=3)

Quiz Test

What does digitize return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.