dimanche 8 mai 2022

Excluding a set of tuples from a ranged random sample in python

I randomly sample N tuples from two different sets of numbers as follows:

set1 = [list(range(10))]
set2 = [list(range(10,20))]

c1 = np.random.choice(set1,N) #ex [9,3,7,8]
c2 = np.random.choice(set2,N) #ex [15,13,19,12]
tuples = np.concatenate([c1,c2],axis=1) #ex [[9,15],[9,19],[3,12]]

For the next iteration I want to sample c1,c2 again but excluding the unique tuples I already have. The numbers can appear again but just not the same combination of (number1,number2). Ideally that would be something like:

new_tuples = np.random.choice([set1,set2],exclude=tuples)

One could just check them with np.unique and resample but I was hopping for it to be a more efficient way.




Aucun commentaire:

Enregistrer un commentaire