jrdioko jrdioko - 1 year ago 253
Python Question

Calculating arithmetic mean (average) in Python

Is there a built-in or standard library method in Python to calculate the arithmetic mean (average) of a list of numbers?

Answer Source

I am not aware of anything in the standard library. However, you could use something like:

float(sum(l))/len(l) if len(l) > 0 else float('nan')

In numpy, there's numpy.mean().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download