Skip to content
Related Articles

Related Articles

Calculate standard deviation of a Matrix in Python

View Discussion
Improve Article
Save Article
  • Last Updated : 26 Nov, 2020
View Discussion
Improve Article
Save Article

In this article we will learn how to calculate standard deviation of a Matrix using Python.

Standard deviation is used to measure the spread of values within the dataset. It indicates variations or dispersion of values in the dataset and also helps to determine the confidence in a model’s statistical conclusions. It is represented by the sigma (σ) and calculates by taking the square root of the variance. If the standard deviation is low it means most of the values are closer to the mean and if high, that means closer to the mean. In this article, we will learn what are the different ways to calculate SD in Python.

We can calculate the Standard Deviation using the following method : 

  1. std() method in NumPy package
  2. stdev() method in Statistics package

Method 1:std() method in NumPy package.


# import required packages
import numpy as np
# Create matrix
matrix = np.array([[33, 55, 66, 74], [23, 45, 65, 27],
                  [87, 96, 34, 54]])
print("Your matrix:\n", matrix)
# use std() method
sd = np.std(matrix)
print("Standard Deviation :\n", sd)

Output :

Your matrix:
[[33 55 66 74]
[23 45 65 27]
[87 96 34 54]]
Standard Deviation :

Method 2: stdev() method in Statistics package.


import statistics
statistics.stdev([11, 43, 56, 77, 87, 45, 67, 33])

Output :

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!