Defined in header <scicpp/core.hpp>
Compute the arithmetic mean.
Compute the arithmetic mean of an array using only the values satisfying the filter predicate.
Compute the arithmetic mean of an array.
Compute the arithmetic mean of an array, ignoring NaNs.
Array
>tmean
(const Array &f, const std::array<T, 2> &limits, const std::array<bool, 2> &inclusive)¶Compute the arithmetic mean of an array, ignoring values outside the given limits. Use the optional parameter inclusive to specify whether the limits are included (by default they are included).
#include <scicpp/core.hpp>
#include <cstdio>
int main()
{
const std::array a{-1., 1., 2., 3.};
// Compute the mean of the array
auto m = scicpp::stats::mean(a);
// Compute the mean of the positive values of the array
auto m_pos = scicpp::stats::mean(a, [](auto x) { return x >= 0; });
printf("m = %f, m_pos = %f\n", m, m_pos);
}