jeudi 22 août 2019

How to create a random sequence excepting a set of given values

I am using numpy and i want to generate an array of size n with random integers from a to b [upper bound exclusive] that are not in the array arr (if it helps, all values in arr are unique). I want the probability to be distributed uniformly among the other possible values. I am aware I can do it in this way:

randlist = np.random.randint(a, b, n)
while np.intersect1d(randlist, arr).size > 0:
    randlist = np.random.randint(a, b, n)

But this seems really inefficent. What would be the fastest way to do this?




Aucun commentaire:

Enregistrer un commentaire