Add support for geometric and harmonic mean #1524
lulunac27a
started this conversation in
Ideas
Replies: 2 comments
-
Super-easy to implement -- great idea @lulunac27a ! :) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Formula for geometric mean in Go: func geometricMean(nums ...float64) {
logSum := 0
count := 0
for _, num := range nums {
logSum += math.Log(num)
count++
}
return math.Exp(logSum / count)
} Formula for harmonic mean in Go: func harmonicMean(nums ...float64) {
reciprocalSum := 0
count := 0
for _, num := range nums {
reciprocalSum += 1/num
count++
}
return count / reciprocalSum
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to calculate the geometric and harmonic mean of a list of numbers. Geometric mean is the product of numbers and finds the root of the product. The harmonic mean is the reciprocal of the average of reciprocals from a list of numbers.
For example:
[3,4,5]
has geometric mean of approximately 3.91((3*4*5)^(1/3))
ore^((ln(3)+ln(4)+ln(5))/3)
, and harmonic mean of approximately 3.83(3/(1/3+1/4+1/5))
Beta Was this translation helpful? Give feedback.
All reactions