NumPy | histogram method
Start your free 7-days trial now!
histogram(~) method computes a histogram (frequency-count diagram).
The input array.
The desired number of bins. If an array is provided, then it must contain edges. By default, we get 10 equal-width bins.
By default, the range is set to (
An array containing the weights placed on each of the input values. If a value falls in a particular bin, instead of incrementing the count by one, we increment by the corresponding weight. The shape must be the same as that of
a. By default, the weights are all one.
Whether to normalise to a probability density function (i.e. total area equaling one). By default,
A tuple of two NumPy arrays:
The values of the histogram (i.e. the frequency counts)
The bin edges
bin_edges represent the intervals of the bins, and the
hist represents the number of values that fall between the interval. For instance, there is a total of one item that falls between the interval
1.9, so we get a value
1 for the spot in the histogram.
Specifying the number of bins
Specifying bin edges
Specifying a range
The reason why we get a 5 there is that the two 6s we have in the input array obviously fall in the same bin, and since their respective weights are 4 and 5, we end up with a total bin count of