Python : easy way to do geometric mean in python?
问题 I wonder is there any easy way to do geometric mean using python but without using python package. If there is not, is there any simple package to do geometric mean? 回答1: The formula of the gemetric mean is: So you can easily write an algorithm like: import numpy as np def geo_mean(iterable): a = np.array(iterable) return a. prod() **(1.0/len(a)) You do not have to use numpy for that, but it tends to perform operations on arrays faster than Python (since there is less "overhead" with casting)