hist!
hist!(counts, v, e) -> e, counts
Compute the histogram of v
, using a vector/range e
as the edges for the bins. This function writes the resultant counts to a pre-allocated array counts
.
Examples
-
Compute and store histogram counts:
julia> counts = zeros(Int, 5); # Pre-allocate array for counts julia> v = [1.2, 2.4, 3.6, 1.2, 4.8, 2.4, 3.6, 4.8]; julia> edges = [0, 2, 4, 6]; # Bins edges julia> hist!(counts, v, edges) 4-element Array{Int64,1}: 2 2 2 2
This example computes the histogram counts of the elements in
v
using the specified bin edgesedges
and stores the counts in the pre-allocatedcounts
array. -
Update histogram counts with new data:
julia> counts = zeros(Int, 4); # Pre-allocate array for counts julia> v = [1, 2, 3, 4, 1, 2, 3, 4]; julia> edges = [0, 1, 2, 3, 4]; # Bins edges julia> hist!(counts, v, edges) 4-element Array{Int64,1}: 2 2 2 2 julia> new_data = [1, 2, 3, 4]; julia> hist!(counts, new_data, edges) 4-element Array{Int64,1}: 4 4 4 4
In this example, the
hist!
function is called twice. The first call computes the histogram counts of the initial data, and the second call updates the counts with new data. Thecounts
array is pre-allocated to store the results.
Common mistake example:
julia> counts = zeros(Int, 5);
julia> v = [1, 2, 3, 4, 5];
julia> edges = [0, 2, 4, 6];
julia> hist!(counts, v, edges)
ERROR: DimensionMismatch("destination array must have the same length as source array")
In this example, the counts
array is not correctly pre-allocated to match the number of bins defined by the edges
array. It's important to ensure that the counts
array has the appropriate length to store the histogram results.
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.