Which gives correct standard deviation ..numpy.std() or statistics.stdev()

Viewed 1146
import statistics
import numpy

speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
print(statistics.stdev(speed))
print(numpy.std(speed))`

#9.636336148089395
#9.258292301032677

why both answers are not same..since it's not same which answer is the correct standard deviation??? please explain someone

2 Answers

I think both are correct. statistics.stdev(speed) makes the calculation using n-1 degrees of freedom and numpy.std(speed) uses n instead. If you're trying to estimate the standard deviation from a population using a sample of data, then you can use statistics.stdev(speed).

For stdev of entire population as in numpy.std() use:

statistics.pstdev()

Related