If you want to calculate variance
in Python, then you are able to do the next.
Choice 1 – Utilizing variance()
from Statistics
module
import statistics
record = [12,14,10,6,23,31]
print("Record : " + str(record))
var = statistics.variance(record)
print("Variance: " + str(var))
Choice 2 – Utilizing var()
from numpy
module
import numpy as np
arr = [12,43,24,17,32]
print("Array : ", arr)
print("Variance: ", np.var(arr))
Choice 3 – Utilizing sum()
and Record Comprehensions
record = [12,43,24,17,32]
common = sum(record) / len(record)
var = sum((x-average)**2 for x in record) / len(record)
print(var)