0% found this document useful (0 votes)
16 views2 pages

Standard Deviation in Python

The document is a Jupyter Notebook focused on calculating variance and standard deviation using Python. It demonstrates generating random numbers, computing mean, variance, and standard deviation both manually and using libraries like NumPy and statistics. The results include a mean of 37.0, standard deviation of approximately 26.8, and variance of about 717.1.

Uploaded by

paulrajarshi7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Standard Deviation in Python

The document is a Jupyter Notebook focused on calculating variance and standard deviation using Python. It demonstrates generating random numbers, computing mean, variance, and standard deviation both manually and using libraries like NumPy and statistics. The results include a mean of 37.0, standard deviation of approximately 26.8, and variance of about 717.1.

Uploaded by

paulrajarshi7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2/24/2020 1.

2_standard_deviation - Jupyter Notebook

Variance and Standard Deviation

In [2]:

import numpy as np
import random

In [3]:

a = np.random.rand(10)

In [11]:

Out[11]:

array([0.41919451, 0.6852195 , 0.20445225, 0.87811744, 0.02738759,


0.67046751, 0.4173048 , 0.55868983, 0.14038694, 0.19810149])

In [4]:

arr = a *100

In [5]:

arr

Out[5]:

array([ 1.2084393 , 72.98372374, 72.75972164, 58.67175435, 51.61508562,


29.4219997 , 21.0268514 , 1.38244609, 19.26872386, 41.52218551])

Calculating Mean, Variance and Standard Deviation

In [6]:

mean = sum(arr)/len(arr)
variance = sum((arr - mean)**2)/len(arr)
stddev = variance ** 0.5

print("Mean={0:0.1f} sd={1:0.1f} and variance={2:0.1f}".format(mean, stddev, variance))

Mean=37.0 sd=25.4 and variance=645.4

localhost:8888/notebooks/Machine Learning/Data Analytics/1.2_standard_deviation.ipynb 1/2


2/24/2020 1.2_standard_deviation - Jupyter Notebook

In [11]:

import statistics as st

# using library another way


stddev2 = st.stdev(arr)

# yet another way


variance2 = st.variance(arr)
stddev3 = np.sqrt(variance2)

In [12]:

print(stddev2)
print(variance2)
print(stddev3)

26.778747047038514
717.1012934092739
26.778747047038514

In [ ]:

localhost:8888/notebooks/Machine Learning/Data Analytics/1.2_standard_deviation.ipynb 2/2

You might also like

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