Defined in header <scicpp/core.hpp>
Compute the histogram of a dataset.
density
= false, bool use_uniform_bins
= false, class InputIt
>histogram
(InputIt first, InputIt last, const std::vector<T> &bins)¶Compute the histogram of a dataset defined by a pair of iterators (first, last)
for a given set of bins
.
If the template parameter density
is true then it returns the probability density, else it returns the bin count (default).
If the bins are uniformly distributed, the template parameter use_uniform_bins
can be set to true to use an efficient algorithm.
Return the histogram.
density
= false, bool use_uniform_bins
= false, class Array
>histogram
(const Array &x, const std::vector<T> &bins)¶Compute the histogram of a dataset defined by an array x
for a given set of bins
.
Return the histogram.
Compute the histogram of a dataset defined by an array x
and compute the bins using a given BinEdgesMethod.
Return a pair [histogram, bins].
Compute the histogram of a dataset defined by an array x
using a number of bins nbins
(default 10).
Return a pair [histogram, bins].
#include <scicpp/core.hpp>
int main() {
using namespace scicpp::stats;
const auto a = std::array{0, 0, 0, 1, 2, 3, 3, 4, 5};
const auto [hist_a, bins_a] = histogram<BinEdgesMethod::AUTO>(a);
scicpp::print(bins_a);
scicpp::print(hist_a);
const auto b = std::vector{0., 1.25, 2.5, 3.75, 5.};
const auto [hist_b, bins_b] = histogram(b, 4);
scicpp::print(bins_b);
scicpp::print(hist_b);
using namespace scicpp::units::literals;
const auto c = std::array{0_V, 0_V, 0_V, 1_V, 2_V, 3_V, 3_V, 4_V, 5_V};
const auto [hist_c, bins_c] = histogram<Density>(c);
scicpp::print(bins_c);
scicpp::print(hist_c);
}