Let’s see how to calculate variance in Numpy python module.
Variance calculations
It is very easy to calculate variance in Python. With Numpy it is even easier.
There is dedicated function in Numpy module to calculate variance.
import numpy as np my_array = np.array([1, 5, 7, 5, 43, 43, 8, 43, 6]) variance = np.var(my_array) print("Variance equals: " + str(round(variance, 2)))
Check also:
how to calculate a Variance in Excel
how to calculate a Variance in Python