Here is a small snippet of code that can be used to compute geometric mean of a set of numbers in Python:
import math
def geomean(listofvalues):
s=0
for v in listofvalues:
s+=math.log10(v)
s=s/len(listofvalues)
s=math.pow(10,s)
return s
# main function
def main():
#test sample
list=[4,4,4,5]
y=geomean(list)
print(y)
# main fucntion call
if __name__ == "__main__":
main()
Aucun commentaire:
Enregistrer un commentaire