SciPy Library

s used for running scientific and mathematical computations. You are specifically going to use a part of the library that implements Gaussian distributions.

Demo: Probability Density Function

from scipy.stats import norm
import numpy as np

# our solution to calculate the probability density function
def gaussian_density(x, mu, sigma):
    return (1/np.sqrt(2*np.pi*np.power(sigma, 2.))) * np.exp(-np.power(x - mu, 2.) / (2 * np.power(sigma, 2.)))

print("Probability density function our solution: mu = 50, sigma = 10, x = 50")
print(gaussian_density(50, 50, 10))
print("\nProbability density function SciPy: mu = 50, sigma = 10, x = 50")
print(norm(loc = 50, scale = 10).pdf(50))

Calculating Probability

Here are a few more examples of the cdf method. The code cell below prints out the probability that the temperature is between:

  • -infinity and 25

  • -infinity and 75

  • -infinity and 125

  • -infinity and +infinity

Last updated

Was this helpful?