Python Practice › NumPy Programs › Program 92
Standard deviation
Write a NumPy program to calculate the standard deviation of an array.
Input
[2, 4, 4, 4, 5, 5, 7, 9]
Output
2.0 2.138
Approach
np.std(population);ddof=1for a sample.
Solution
import numpy as npa = np.array([2, 4, 4, 4, 5, 5, 7, 9])print(np.std(a), round(float(np.std(a, ddof=1)), 3))Output
2.0 2.138
Learn the concept
New to this topic? Read the lesson, then come back.