# xhistogram¶

Defined in xtensor/xhistogram.hpp

enum xt::histogram_algorithm

Defines different algorithms to be used in “histogram_bin_edges”.

Values:

automatic
linspace
logspace
uniform
template<class R = double, class E1, class E2, class E3>
auto xt::histogram(E1 &&data, E2 &&bin_edges, E3 &&weights, bool density = false)

Compute the histogram of a set of data.

Return

An one-dimensional xarray<double>, length: bin_edges.size()-1.

Parameters
• data: The data.

• bin_edges: The bin-edges. It has to be 1-dimensional and monotonic.

• weights: Weight factors corresponding to each data-point.

• density: If true the resulting integral is normalized to 1. [default: false]

template<class E1, class E2, xtl::check_concept<is_xexpression<std::decay_t<E2>>> = 0>
auto xt::bincount(E1 &&data, E2 &&weights, std::size_t minlength = 0)

Count number of occurrences of each value in array of non-negative ints.

The number of bins (of size 1) is one larger than the largest value in x. If minlength is specified, there will be at least this number of bins in the output array (though it will be longer if necessary, depending on the contents of x). Each bin gives the number of occurrences of its index value in x. If weights is specified the input array is weighted by it, i.e. if a value n is found at position i, out[n] += weight[i] instead of out[n] += 1.

Return

1D container with the bincount

Parameters
• data: the 1D container with integers to count into bins

• weights: a 1D container with the same number of elements as data

• minlength: The minlength

template<class E1, class E2, class E3>
auto xt::histogram_bin_edges(E1 &&data, E2 &&weights, E3 left, E3 right, std::size_t bins = 10, histogram_algorithm mode = histogram_algorithm::automatic)

Compute the bin-edges of a histogram of a set of data using different algorithms.

Return

An one-dimensional xarray<double>, length: bins+1.

Parameters
• data: The data.

• weights: Weight factors corresponding to each data-point.

• left: The lower-most edge.

• right: The upper-most edge.

• bins: The number of bins. [default: 10]

• mode: The type of algorithm to use. [default: “auto”]

template<class E1, class E2>
auto xt::digitize(E1 &&data, E2 &&bin_edges, bool right = false)

Return the indices of the bins to which each value in input array belongs.

Return

Output array of indices, of same shape as x.

Parameters
• data: The data.

• bin_edges: The bin-edges. It has to be 1-dimensional and monotonic.

• right: Indicating whether the intervals include the right or the left bin edge.

template<class E>
xt::xtensor<size_t, 1> xt::bin_items(size_t N, E &&weights)

Get the number of items in each bin, given the fraction of items per bin.

The output is such that the total number of items of all bins is exactly “N”.

Return

1D container with the number of items per bin

Parameters
• N: the number of items to distribute

• weights: fraction of items per bin: a 1D container whose size is the number of bins

template<class R = double, class E1, class E2>
auto xt::histogram(E1 &&data, E2 &&bin_edges, bool density = false)

Compute the histogram of a set of data.

Return

An one-dimensional xarray<double>, length: bin_edges.size()-1.

Parameters
• data: The data.

• bin_edges: The bin-edges.

• density: If true the resulting integral is normalized to 1. [default: false]

template<class R = double, class E1>
auto xt::histogram(E1 &&data, std::size_t bins = 10, bool density = false)

Compute the histogram of a set of data.

Return

An one-dimensional xarray<double>, length: bin_edges.size()-1.

Parameters
• data: The data.

• bins: The number of bins. [default: 10]

• density: If true the resulting integral is normalized to 1. [default: false]

template<class R = double, class E1, class E2>
auto xt::histogram(E1 &&data, std::size_t bins, E2 left, E2 right, bool density = false)

Compute the histogram of a set of data.

Return

An one-dimensional xarray<double>, length: bin_edges.size()-1.

Parameters
• data: The data.

• bins: The number of bins.

• left: The lower-most edge.

• right: The upper-most edge.

• density: If true the resulting integral is normalized to 1. [default: false]

template<class R = double, class E1, class E2>
auto xt::histogram(E1 &&data, std::size_t bins, E2 &&weights, bool density = false)

Compute the histogram of a set of data.

Return

An one-dimensional xarray<double>, length: bin_edges.size()-1.

Parameters
• data: The data.

• bins: The number of bins.

• weights: Weight factors corresponding to each data-point.

• density: If true the resulting integral is normalized to 1. [default: false]

template<class R = double, class E1, class E2, class E3>
auto xt::histogram(E1 &&data, std::size_t bins, E2 &&weights, E3 left, E3 right, bool density = false)

Compute the histogram of a set of data.

Return

An one-dimensional xarray<double>, length: bin_edges.size()-1.

Parameters
• data: The data.

• bins: The number of bins.

• left: The lower-most edge.

• right: The upper-most edge.

• weights: Weight factors corresponding to each data-point.

• density: If true the resulting integral is normalized to 1. [default: false]

template<class E1, class E2>
auto xt::histogram_bin_edges(E1 &&data, E2 left, E2 right, std::size_t bins = 10, histogram_algorithm mode = histogram_algorithm::automatic)

Compute the bin-edges of a histogram of a set of data using different algorithms.

Return

An one-dimensional xarray<double>, length: bins+1.

Parameters
• data: The data.

• left: The lower-most edge.

• right: The upper-most edge.

• bins: The number of bins. [default: 10]

• mode: The type of algorithm to use. [default: “auto”]

template<class E1, class E2>
auto xt::histogram_bin_edges(E1 &&data, E2 &&weights, std::size_t bins = 10, histogram_algorithm mode = histogram_algorithm::automatic)

Compute the bin-edges of a histogram of a set of data using different algorithms.

Return

An one-dimensional xarray<double>, length: bins+1.

Parameters
• data: The data.

• weights: Weight factors corresponding to each data-point.

• bins: The number of bins. [default: 10]

• mode: The type of algorithm to use. [default: “auto”]

template<class E1>
auto xt::histogram_bin_edges(E1 &&data, std::size_t bins = 10, histogram_algorithm mode = histogram_algorithm::automatic)

Compute the bin-edges of a histogram of a set of data using different algorithms.

Return

An one-dimensional xarray<double>, length: bins+1.

Parameters
• data: The data.

• bins: The number of bins. [default: 10]

• mode: The type of algorithm to use. [default: “auto”]

xt::xtensor<size_t, 1> xt::bin_items(size_t N, size_t bins)

Get the number of items in each bin, with each bin having approximately the same number of items in it,under the constraint that the total number of items of all bins is exactly “N”.

Return

1D container with the number of items per bin

Parameters
• N: the number of items to distribute

• bins: the number of bins