Open In App

Calculate standard deviation of a Matrix in Python

Last Updated : 26 Nov, 2020
Comments
Improve
Suggest changes
Like Article
Like
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

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy