6.3 The Standard Deviation
The standard deviation is the square root of the variance.
- The sample variance of the data set is given by
numpy for sample standard deviation:
import numpy as np
x = [x1,x2,x3,...]
np.std(x,ddof=1)
- The population variance of the data set is given by
numpy for population standard deviation:
import numpy as np
x = [x1,x2,x3,...]
np.std(x)
Example: find the sample standard deviation (std) of the data set 1,2,3,4,5
import numpy as np
x = [1,2,3,4,5]
np.std(x,ddof=1)
Show expected output
1.5811388300841898Interpretation: The sample standard deviation is 1.5811388300841898
Example: find the population standard deviation of the data set 1,2,3,4,5
import numpy as np
x = [1,2,3,4,5]
np.std(x)
Show expected output
1.4142135623730951Interpretation: The population standard deviation is 1.4142135623730951
Example: The 2010 life expectancy of the 77 Chicago community areas are listed below. Write a numpy program to compute the population standard devaition.
77.3, 80.3, 76, 80.5, 81.5, 81.9, 81.3, 85.2, 81, 80.9, 79.7, 83.4, 84.4, 80.6, 80.3, 79.6, 79.8, 79.6, 79.5, 80.5, 79.8, 80.3, 74.5, 79.5, 71.9, 68.8, 71.7, 78.9, 72.1, 82.2, 81.4, 85, 80.6, 81.9, 74.1, 73.6, 69.8, 74.1, 80.5, 68.9, 82.3, 74.5, 72.5, 74, 74.7, 72.7, 71.9, 77.1, 72.9, 76.4, 76.2, 78.4, 71.6, 76.4, 77.1, 79.8, 79.5, 80.8, 80.4, 80.2, 74.4, 81, 79.2, 77.5, 80.5, 75.2, 70.1, 70.7, 71.1, 78.2, 72.6, 80.5, 74.9, 79.6, 75.3, 82.2, 79.8, 77.8
import numpy as np
x = [77.3, 80.3, 76, 80.5, 81.5, 81.9, 81.3, 85.2, 81, 80.9, 79.7, 83.4, 84.4,
80.6, 80.3, 79.6, 79.8, 79.6, 79.5, 80.5, 79.8, 80.3, 74.5, 79.5, 71.9,
68.8, 71.7, 78.9, 72.1, 82.2, 81.4, 85, 80.6, 81.9, 74.1, 73.6, 69.8, 74.1,
80.5, 68.9, 82.3, 74.5, 72.5, 74, 74.7, 72.7, 71.9, 77.1, 72.9, 76.4, 76.2,
78.4, 71.6, 76.4, 77.1, 79.8, 79.5, 80.8, 80.4, 80.2, 74.4, 81, 79.2, 77.5,
80.5, 75.2, 70.1, 70.7, 71.1, 78.2, 72.6, 80.5, 74.9, 79.6, 75.3, 82.2,
79.8, 77.8]
np.std(x,ddof=0)
Show expected output
4.036198185451496Example: A random sample of 35 annual salaries of Animal Control employees of the City of Chicago is listed below. Write a numpy program to compute the sample variance and standard deviation.
45288, 96096, 69468, 79872, 92520, 49968, 76248, 110076, 84324, 101496, 100668, 66864, 49968, 101496, 49968, 69468, 69468, 96096, 100716, 73380, 52044, 76248, 66864, 66864, 76848, 66864, 139392, 56280, 69468, 66864,73380, 87564, 49968, 49968, 76848
import numpy as np
x = [45288, 96096, 69468, 79872, 92520, 49968, 76248, 110076, 84324, 101496,
100668, 66864, 49968, 101496, 49968, 69468, 69468, 96096, 100716, 73380,
52044, 76248, 66864, 66864, 76848, 66864, 139392, 56280, 69468, 66864,
73380, 87564, 49968, 49968, 76848]
print('The sample variance and standard deviation are')
print(np.var(x,ddof=1))
print(np.std(x,ddof=1))
Show expected output
The sample variance and standard deviation are
438099876.7865547
20930.835549173727Interpretation: The sample variance and standard deviation are 438099876.7865547 and 20930.835549173727 respectively.
Interpretation: The population standard deviation is 4.036198185451496
Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.