Given a list of tuples a :
a =[(23, 11), (10, 16), (13, 11), (12, 3), (4, 15), (10, 16), (10, 16)]
We can calculate how many cells of each tuple we use Counter :
>>> from collections import Counter >>> b = Counter(a) >>> b Counter({(4, 15): 1, (10, 16): 3, (12, 3): 1, (13, 11): 1, (23, 11): 1}
Now the idea is to select 3 random tuples from the list without repeating, so that the counter determines the probability of choosing a particular tuple.
For example, (10, 16) is more likely to be chosen than others - its weight is 3/7, while the other four tuples are 1/7.
I tried using np.random.choice :
a[np.random.choice(len(a), 3, p=b/len(a))]
But I can not generate tuples.
I'm trying to:
a =[(23, 11), (10, 16), (13, 11), (10, 16), (10, 16), (10, 16), (10, 16)] b = Counter(a) c = [] print "counter list" print b for item in b: print "item from current list" print item print "prob of the item" print (float(b[item])/float(len(a))) c.append(float(b[item])/float(len(a))) print "prob list" print c print (np.random.choice(np.arange(len(b)), 3, p=c, replace=False))
In this case, im gets random array indices.