Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

random sampling from a list based on a distribution

I have a list of numbers, and would like to sample from that list. The sampling however is based on some distribution which is specified by a user. I am not sure if alias method (here) using weights is the right one; my limited knowledge says alias method uses uniform distribution alone (correct me on that please!). What if I need to specify something like sample using log-normal as the underlying distribution or poisson for that matter? How do I do this kind of sampling?

A related question, if my list is say [1, 2, 3, 4, 5] and mean is 3, how do I get the sampling?

like image 338
okkhoy Avatar asked Feb 06 '26 10:02

okkhoy


1 Answers

Have you tried np.random.choice

b = np.random.choice(a=[1,2,3,4,5], p=[0.2, 0.2, 0.2, 0.2, 0.2])

b is randomly sampled from a based on the distribution p

You can also use poisson

like image 62
Kenan Avatar answered Feb 09 '26 00:02

Kenan