0

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?

tfreak
  • 123
  • 9
  • https://stackoverflow.com/questions/3679694/a-weighted-version-of-random-choice – Compsci is math base 2 Jul 21 '20 at 01:49
  • @Compsciismathbase2 The answers do not explain how the probability distribution is or the answers only explain when the pre-defined probability is given. I think generating exponential/geometric distribution before the ```p``` can be used. – tfreak Jul 22 '20 at 09:52

0 Answers0