Computing the cumulative distribution function for a random variable
In the previous section, we looked at the probability distribution of a continuous random variable.
In the next section, we will consider the cumulative distribution of a continuous random variable.
How to do it...
The cumulative distribution function (CDF) of a random variable is calculated as follows:
The CDF of a continuous random variable is calculated in a way similar to that in which we calculate the pdf of a continuous random variable.
The following code snippet calculates the CDF of a variable:
- Import the relevant packages:
import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm
- Calculate the CDF of the variable:
gaussian = norm(loc=0, scale=1.0) x = np.linspace(-5, 5, 1000) y = gaussian.cdf(x)
In the preceding snippet of code, we have calculated the CDF for the continuous random variable that is expected to generate a Gaussian distribution with a mean of 0 and a standard deviation of 1.
Note that we...