calculate variance python code example
Example 1: numpy how to calculate variance
import numpy
numbers = [50,66,77,88,99,100]
x = numpy.var(numbers)
print(x)
Example 2: python calculate variance by hand
# calculate mean
m = sum(results) / len(results)
# calculate variance using a list comprehension
var_res = sum((xi - m) ** 2 for xi in results) / len(results)