dimanche 31 mars 2019

cumulative weights in random.choices

Apologies if this has been asked before but I am new to Python and confused using the new 'random.choices' in python 3.7(?).

Here is the doc. https://docs.python.org/3/library/random.html

random.choices(population, weights=None, *, cum_weights=None, k=1)

-- Return a k sized list of elements chosen from the population with replacement. If the population is empty, raises IndexError.

2 questions:

  1. Where can I find full documentation (similar to Matlab's mathworks.com) instead of just the single line given above?

  2. They give an example: weights=[10, 5, 30, 5] and I don't know what this means? Why don't they sum to 100? If my population is [1, 2, 3, 4] -- does this mean that a choice of '10' occurs with probability 0.1?

Thank you. And I apologies again for breaking any of the posting/asking etiquettes here.

Best,

HP




Aucun commentaire:

Enregistrer un commentaire