I have a Numpy array and I would like to use statistics.stdev() to compute its standard deviation. The output of this operation is somewhat unexpected.
import numpy as np
from statistics import stdev, pstdev
>>> a = np.array([0, 1, 2, 3])
>>> stdev(a)
1.0
This is neither the sample standard deviation
>>> stdev([0, 1, 2, 3])
1.2909944487358056
nor the population standard deviation
>>> pstdev([0, 1, 2, 3])
1.118033988749895
I wonder if statistics.stdev() is not supposed to work with Numpy arrays or there is some underlying mechanism causing this behavior?
Note that np.std() works both on lists and Numpy arrays.
>>> np.std([0, 1, 2, 3])
1.118033988749895
>>> np.std(np.array([0, 1, 2, 3]))
1.118033988749895
Both give the population standard deviation as expected.