
NumPy std: How to calculate the standard deviation in Python
Standard deviation is calculated by numpy.std
in Python. The value of standard deviation has the float type.
import numpy
a = numpy.array([1, 2, 3])
s = numpy.std(a)
print(s) # 0.816496580927726
print(type(s)) # <class 'numpy.float64'>
numpy.std
takes a numpy.array, list or tuple.
import numpy
a1 = numpy.array([1, 2, 3])
a2 = [1, 2, 3]
a3 = (1, 2, 3)
s1 = numpy.std(a1)
s2 = numpy.std(a2)
s3 = numpy.std(a3)
print(s1) # 0.816496580927726
print(s2) # 0.816496580927726
print(s3) # 0.816496580927726
Comments
Powered by Markdown