Reputation: 31
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
Upvotes: 3
Views: 4405
Reputation: 3598
For stdev of entire population as in numpy.std()
use:
statistics.pstdev()
Upvotes: 3
Reputation: 598
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)
.
Upvotes: 1