In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
Assume the following distribution:
Outcome
Probability
1
0.05
2
0.1
4
0.05
5
0.1
7
0.3
8
0.4
1. fill in the following cell to generate a u and convert u to a sample value from the distribution above.
In [3]:
Outcome=np.array([1,2,4,5,7,8])
PMF=np.array([0.05,0.1,0.05,0.1,0.3,0.4])
u=np.random.rand()
# calcultae CDF from PMF
CDF=np.cumsum(PMF)
# conversion
for i in range(len(Outcome)):
if u