In Numpy
we can use np.random.choice(N, data.shape[0], p=[0.6, 0.2, 0.1, 0.05, 0.05])
to randomly generate random samples. When the number of N is small, I can fill p
manually. However, how to generate p
automatically with that non-uniform distribution, e.g., the probability decreases from left to right or vice versa, when N is big, e.g., N=50 or N=100?
As far as I know, the following method can generate p
automatically, however it seems that the result is still a uniform distribution.
values = [np.random.rand() for _ in range(N)]
p = [v/sum(values) for v in values]
How to obtain this kind of p=[0.6, 0.2, 0.1, 0.05, 0.05]
automatically?