Computes the arithmetic mean (average) of the given numbers. The arithmetic mean is calculated as: (x₁ + x₂ + ... + xₙ) / n Example: For numbers [2, 4, 6], the arithmetic mean is (2+4+6)/3 = 4.0 @param numbers the input numbers (must not be empty) @return the arithmetic mean of th
(final Iterable<Double> numbers)
| 47 | * Mean</a> |
| 48 | */ |
| 49 | public static Double arithmetic(final Iterable<Double> numbers) { |
| 50 | checkIfNotEmpty(numbers); |
| 51 | double sum = StreamSupport.stream(numbers.spliterator(), false).reduce(0d, (x, y) -> x + y); |
| 52 | int size = IterableUtils.size(numbers); |
| 53 | return sum / size; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Computes the geometric mean of the given numbers. |