Python Practice › NumPy Programs › Program 92

Standard deviation

EasyNumPy Programs · 92 of 100

Write a NumPy program to calculate the standard deviation of an array.

Advertisement
Input
[2, 4, 4, 4, 5, 5, 7, 9]
Output
2.0 2.138

Approach

  1. np.std (population); ddof=1 for a sample.

Solution

Python
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.

More numpy programs

← All 100 NumPy Programs

Leave a Comment