In the above examples, I had prior knowledge that my data was normally distributed, which is why I used () - there are multiple distributions scipy supports. X = np.random.multivariate_normal(mean=mu, cov=cov, size=1000) # 1000 samples # generate 2d normally distributed samples using 0 mean and the covariance matrix above The same method to calculate the cdf also works for multiple dimensions: we use 2d data below to illustrate mu = np.zeros(2) # mean vectorĬov = np.array(,]) # covariance matrix
> array() We can even print the first few values of the cdf to show they are discrete print(norm_cdf) Norm_cdf = (x) # calculate the cdf - also discrete X = np.random.randn(10000) # generate samples from normal distribution (discrete data)
you know the pdf of your data), then scipy does support discrete data when calculating cdf's import numpy as np
This function is easy to invert, and it depends on your application which form you need.Īssuming you know how your data is distributed (i.e. It should reflect the CDF of the process behind the points, but naturally, it is not as long as the number of points is finite. This gives the following plot where the right-hand-side plot is the traditional cumulative distribution function. # calculate the proportional values of samples # create some randomly ddistributed data: Let us have a closer look at this with a simple example: import matplotlib.pyplot as plt If you want to know the value at 50 % of the distribution, just look at the array element which is in the middle of the sorted array. If you look at the sorted result, you'll realize that the smallest value represents 0%, and largest value represents 100 %. If you have a discrete array of samples, and you would like to know the CDF of the sample, then you can just sort the array. If the array is not equispaced, then np.cumsum of the array multiplied by the distances between the points will do.)
If the question is how to get from a discrete PDF into a discrete CDF, then np.cumsum divided by a suitable constant will do if the samples are equispaced. (It is possible that my interpretation of the question is wrong.