etl/docs/maths/mean.md
2026-04-16 12:40:36 +02:00

1.5 KiB

title
mean

{{< callout type="info">}} Header: mean.h
Since: 20.9.0
{{< /callout >}}

template <typename TInput, typename TCalc = TInput>
class mean : public etl::unary_function<TInput, void> 

TInput The input data type. TCalc The type to use for internal calculations. By default, equal to TInput.


mean()

Description
Default constructor.


template <typename TIterator>
mean(TIterator first, TIterator last)

Description
Construct from an iterator range.


void add(TInput value1)

Description
Add a value.


template <typename TIterator>
void add(TIterator first, TIterator last)

Description
Add a range of values.


void operator()(TInput value)

Description
Add a values.


template <typename TIterator>
void operator()(TIterator first, TIterator last)

Description
Add a range of values.


double get_mean() const

Description
Returns the calculated mean for the data.


operator double() const

Return
The calculated mean for the data.


size_t count() const

Description
Get the total number added entries.


void clear()

Description
Clear the mean.

Example

std::array<char, 10> input
{
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
};

etl::mean<char, int32_t> mean(input.begin(), input.end());

double mean_result;

mean_result = mean; // mean_result  == 4.5