xhistogram

Defined in xtensor/xhistogram.hpp

enum class xt::histogram_algorithm

Defines different algorithms to be used in “histogram_bin_edges”.

Values:

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

Compute the histogram of a set of data.

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]

Returns:

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

template<class E1, class E2, xtl::check_concept<is_xexpression<std::decay_t<E2>>> = 0>
inline 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.

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

Returns:

1D container with the bincount

template<class E1, class E2, class E3>
inline 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.

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”]

Returns:

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

Warning

doxygenfunction: Unable to resolve function “xt::digitize” with arguments (E1&&, E2&&, E3&&, bool, bool) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class E1, class E2> auto digitize(E1 &&data, E2 &&bin_edges, bool right = false)
template<class E>
inline 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”.

Parameters:
  • N – the number of items to distribute

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

Returns:

1D container with the number of items per bin

Further overloads

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

Compute the histogram of a set of data.

Parameters:
  • data – The data.

  • bin_edges – The bin-edges.

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

Returns:

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

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

Compute the histogram of a set of data.

Parameters:
  • data – The data.

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

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

Returns:

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

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

Compute the histogram of a set of data.

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]

Returns:

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

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

Compute the histogram of a set of data.

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]

Returns:

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

template<class R = double, class E1, class E2, class E3>
inline 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.

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]

Returns:

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

template<class E1, class E2>
inline 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.

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”]

Returns:

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

template<class E1, class E2>
inline 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.

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”]

Returns:

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

template<class E1>
inline 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.

Parameters:
  • data – The data.

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

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

Returns:

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

inline 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”.

Parameters:
  • N – the number of items to distribute

  • bins – the number of bins

Returns:

1D container with the number of items per bin