Domanda

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?

È stato utile?

Soluzione

Try numpy.random.choice:

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

Altri suggerimenti

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? ...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top