mean

Computes the arithmetic mean of the values in this iterable.

The arithmetic mean is the sum of all values divided by the count. Uses compensated (Neumaier) summation for improved numerical precision.

NaN values propagate through the computation (IEEE 754 semantics): if any element is NaN, the result is NaN. Filter NaN values before calling this function if that is not desired.

Example:

listOf(1.0, 2.0, 3.0).mean() // 2.0

Return

the arithmetic mean of the elements.


Computes the arithmetic mean of the values in this array.

The arithmetic mean is the sum of all values divided by the count. Uses compensated (Neumaier) summation for improved numerical precision with large arrays.

NaN values propagate through the computation (IEEE 754 semantics): if any element is NaN, the result is NaN. Filter NaN values before calling this function if that is not desired.

Example:

doubleArrayOf(1.0, 2.0, 3.0).mean() // 2.0

Return

the arithmetic mean of the array elements.


Computes the arithmetic mean of the values in this sequence.

The arithmetic mean is the sum of all values divided by the count. Uses compensated (Neumaier) summation for improved numerical precision. The sequence is consumed once.

NaN values propagate through the computation (IEEE 754 semantics): if any element is NaN, the result is NaN. Filter NaN values before calling this function if that is not desired.

Example:

sequenceOf(1.0, 2.0, 3.0).mean() // 2.0

Return

the arithmetic mean of the elements.


@JvmName(name = "meanOfLong")
fun Iterable<Long>.mean(): Double(source)

Computes the arithmetic mean of the Long values.

Values are converted to Double internally. Long values whose absolute value exceeds 2^53 (9,007,199,254,740,992) may lose precision in the least-significant digits.

Example:

listOf(1L, 2L, 3L).mean() // 2.0

Return

the arithmetic mean of the Long values as a Double.


@JvmName(name = "meanOfInt")
fun Iterable<Int>.mean(): Double(source)

Computes the arithmetic mean of the Int values.

Values are converted to Double internally. The conversion is exact for all Int values.

Example:

listOf(1, 2, 3).mean() // 2.0

Return

the arithmetic mean of the Int values as a Double.