jeudi 12 mars 2015

use np.random.multinomial() in python

I have a task to randomly chose 100 element from a population of alpha list [a,b,c,d] with corresponding frequency (probability) [0.1, 0.3, 0.2, 0.4]. There are many different ways to do it. But here I want what returned after this function call (suppose there is one) is a list of the number of elements choosen. Say, it returns (20,20,30,30), then it means 20 of elements a are choosen, 20 of elements c are choosen, etc. I figured that np.random.multinomial is the way to go. Following the above example, I will need to call the function np.random.multinomial(100, [0.1,0.3,0.2,0.4],1 ). Is this right ? Thanks.


Related: fast way to uniformly remove 10% of all the elements in a given list of python





Aucun commentaire:

Enregistrer un commentaire