All problems
Geometric Mean
Problem
Return the geometric mean of positive values: exp(mean(ln(x))). Return 0.0 if data is empty or contains a non-positive value.
Hint
Take logs, average them, then exponentiate.
Test cases
case 1
in: [[1,4,16]]
expected: 4
case 2
in: [[2,8]]
expected: 4
case 3
in: [[5]]
expected: 4.999999999999999
case 4
in: [[1,2,4,8]]
expected: 2.82842712474619
case 5
in: [[0,1]]
expected: 0
Starter codePython
import math
def geometric_mean(data):
# Your code here
pass5 test cases · run your code against them in the editor