Standard Deviation
Standard Deviation is the square root of variance. It is a measure of the extent to which data varies from the mean. The mathematical formula for calculating standard deviation is as follows,
Example:
Standard Deviation for the above data,
Standard Deviation in Python Using Numpy:
One can calculate the standard deviation by using numpy.std() function in python.
Syntax:
numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=<no value>)
Parameters:
a: Array containing data to be averaged
axis: Axis or axes along which to average a
dtype: Type to use in computing the variance.
out: Alternate output array in which to place the result.
ddof: Delta Degrees of Freedom
keepdims: If this is set to True, the axes which are reduced are left in the result as dimensions with size one
Example 1:
Python
# Python program to get # standard deviation of a list # Importing the NumPy module import numpy as np # Taking a list of elements list = [ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 ] # Calculating standard # deviation using var() print (np.std( list )) |
Output:
2.0
Example 2:
Python
# Python program to get # standard deviation of a list # Importing the NumPy module import numpy as np # Taking a list of elements list = [ 290 , 124 , 127 , 899 ] # Calculating standard # deviation using var() print (np.std( list )) |
Output:
318.35750344541907
Calculate the average, variance and standard deviation in Python using NumPy
Numpy in Python is a general-purpose array-processing package. It provides a high-performance multidimensional array object and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Numpy provides very easy methods to calculate the average, variance, and standard deviation.