I have an array of binaries ... what I want is to be able to pick a specific percentage of ones from every row ... f.e. let say the number of ones are 100 per row, I want to get back randomly 20% from the first row, 10% from the second, 40% 3rd, 30% from 4rd (total 100% of course).
0| 00000000001000000010000000000000000000001000000100000000000000000000000000000001 ...
1| 00000000000000010000000000001000000000000100000000000000000000000000000000000000 ...
2| 00000000000000000000000000000010010000000000000000000000000000010000100000000000 ...
3| 01000000000000100000000000000000000000001000100000000000000010000000000000000000 ...
that is easy just do random.choice(one_idxs, %) on every row. The problem is that the target number of bits has to be 100 too .. i.e. if some bits overlap and random selection picks them the total number will be different than 100 bits.
Plus on every row it should try to pick bits which were not selected previously at least as an option !
Any idea
Ex. code I use for the straightforward case, (which does not account if the selected indexes repeat across rows, just within a row) :
for every row :
ones_count = 100
bits_cnt = int(ones_count * probs[i])
idxs = array.get_row(i).one_idxs()
selected = np.random.choice(idxs, size=bits_cnt, replace=False)
Aucun commentaire:
Enregistrer un commentaire