hist(v,e)
hist(v, e) -> e, counts
Compute the histogram of v
using a vector/range e
as the edges for the bins. The result will be a vector of length length(e) - 1
, such that the element at location i
satisfies sum(e[i] .< v .<= e[i+1])
. Note: Julia does not ignore NaN
values in the computation.
Examples
-
Compute histogram with default number of bins:
julia> v = [1, 2, 1, 3, 2, 4, 1, 2, 3]; julia> e, counts = hist(v) ([1, 2, 3, 4], [3, 3, 2])
This example computes the histogram of the vector
v
using the default number of bins. It returns the rangee
which represents the edges of the bins, andcounts
which contains the count of elements in each bin. -
Compute histogram with a specific number of bins:
julia> v = [1.5, 2.7, 3.8, 4.9, 5.5]; julia> e, counts = hist(v, 3) ([1.5, 3.0, 4.5, 6.0], [1, 1, 3])
This example computes the histogram of the vector
v
using 3 bins. It returns the rangee
with the bin edges andcounts
with the count of elements in each bin. - Handle NaN values in the computation:
julia> v = [1, 2, NaN, 3, 4, NaN, 5]; julia> e, counts = hist(v) ([1.0, 2.0, 3.0, 4.0, 5.0], [1, 1, 1, 1, 1])
The
hist
function does not ignoreNaN
values in the computation. It treats them as separate elements in the histogram.
Common mistake example:
julia> v = [1, 2, 3, 4, 5];
julia> e, counts = hist(v, -2)
ERROR: ArgumentError: number of bins must be non-negative
In this example, a negative number of bins is provided, which is not allowed. Ensure that the number of bins is a non-negative integer when using the hist
function.
See Also
cummax, eigmax, findmax, hist, hist!, hist2d, hist2d!, histrange, indmax, maxabs, maxabs!, maximum!, mean, mean!, median, median!, minabs, minabs!, minimum!, minmax, quantile!, realmax, std, stdm,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.