lundi 18 juillet 2022

Random Choice with different distributions for each sample

Image we want to randomly get n times 0 or 1. But every time we make a random choice we want to give a different probability distribution.

Considering np.random.choice:

a = [0, 1] or just 2
size = n
p = [
        [0.2, 0.4],
        [0.5, 0.5],
        [0.7, 0.3]
] # For instance if n = 3

The problem is that len(a) has to be equal to len(p). How can we make something like this without having to call np.random.choice n different times?

The reason why I need to do this without calling np.random.choice multiple times is that I want an output of size n using a seed for reproducibility. However if I call np.random.choice n times with a seed the randomness is lost within the n calls.




Aucun commentaire:

Enregistrer un commentaire