jeudi 8 juin 2017

Choosing more than 1 element from the list

I am trying to make a choice for each element in elements, and then I am pairing up the element in elements list with its preferential choice(one,two or three). The choice is mostly done regarding the probabilities (weights) of the elements. The code until here:

    from numpy.random import choice
    elements = ['one', 'two', 'three']
    weights = [0.2, 0.3, 0.5]
    chosenones= []
    for el in elements:
        chosenones.append(choice(elements,p=weights))
    tuples = list(zip(elements,chosenones))

Yields:

[('one', 'two'), ('two', 'two'), ('three', 'two')]

What I need is, for each element to make two choices instead of one.

The expected output should look like:

[('one', 'two'), ('one', 'one'), ('two', 'two'),('two', 'three'), ('three', 'two'), ('three', 'one')]

Do you know how to do have this output?




Aucun commentaire:

Enregistrer un commentaire