I have a 2 column array, 1st column weights and the 2 nd column values which I am plotting using python. I would like to draw 20 samples from this weighted array, proportionate to their weights. Is there a python/numpy command which does that?

有帮助吗?

解决方案

Try numpy.random.choice:

your_samples = numpy.random.choice(your_array[1], size=20, replace=False,
                                   p=your_array[0])

其他提示

You need to refine your problem statement better. For example, if your array has only 1 row, what do you expect. If your array has 20,000 rows what do you expect? ...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top