You can use the numpy var built-in function:
import numpy as np results = [-14.82381293, -0.29423447, -13.56067979, -1.6288903, -0.31632439, 0.53459687, -1.34069996, -1.61042692, -4.03220519, -0.24332097] print(np.var(results))
This gives you 28.822364260579157
If - for some reason - you cannot use numpy and / or you do not want to use the built-in function for it, you can also calculate it "manually" using, for example, list comprehension :
# calculate mean m = sum(results) / len(results)
which gives you an identical result.
If you are interested in standard deviation , you can use numpy.std :
print(np.std(results)) 5.36864640860051
@ Serge Ballesta very well explained the difference between the variance of n and n-1 . In numpy, you can easily set this parameter using the ddof option; the default is 0 , so for case n-1 you can just do:
np.var(results, ddof=1)
The freehand solution is provided in @Serge Ballesta's answer .
Both approaches give 32.024849178421285 .
You can set the parameter also for std :
np.std(results, ddof=1) 5.659050201086865