Login
📚 Python for Introductory Statistics
Chapters ▾

8.1 Expected Values and Standard Deviations

Watch demo video

If the probability distribution of the random variable X is given by p(x), then:

  1. The expected value of a random variable X is given by E(X)=μ=Σxp(x)
  2. The standard deviation of the random variable X is given by σ=E(Xμ)2=Σ(xμ)2p(x)

Syntax for expected value

import numpy as np
np.average(x, weights=prob)

Syntax for population standard deviation

import numpy as np
np.sqrt(np.cov(x, aweights=prob, ddof=0))

Example: The number of electronic devices per household in a neighborhood and their corresponding probabilities are given on the table below. Find the expected value and standard deviation of the number of devices per household in this neighborhood.

xp(x)
0.01
1.02
2.13
3.33
4.51
import numpy as np

x = [0,1,2,3,4]
prob = [.01,.02,.13,.33,.51]

expected_value = np.average(x,weights=prob)
expected_value
Show expected output
3.31

Interpretation: The mean number of electronic devices per household is 3.31.

import numpy as np

x = [0,1,2,3,4]
prob = [.01,.02,.13,.33,.51]

standard_deviation = np.sqrt(np.cov(x, aweights=prob, ddof=0))
standard_deviation
Show expected output
0.8449260322655469

Interpretation: The mean number of electronic devices per household is 3.31 with a standard deviation of 0.845.

Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.