Search code examples
pythonrandom

Random Sampling with different probabilities


I'm pretty new to python and maybe this is a very silly/stupid question, but I've got a tremendous headache from thinking about this problem.

I got a set of data, for example integers, from which I want to extract a random subset, but every object has a different probability. How can I extract the subset in a way that respect the probability distribution of the data?

I suppose that np.random_sample gives to all samples the same priority, so its not what I'm looking for...


Solution

  • numpy.random.choice has a p parameter that lets you set probabilities for the different objects.