Open In App
Related Articles

Calculate standard deviation of a Matrix in Python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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.

Python3

# 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 :
22.584870796373593

Method 2: stdev() method in Statistics package.

Python3

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

                    

Output :

24.67466890789592


Last Updated : 26 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads