I have two list: A with the size of 49 and B with the size of 68.
I want to iterate over all possible subsamples in the size of 32 in the lists.
What is the best way to do it in python?
I have two list: A with the size of 49 and B with the size of 68.
I want to iterate over all possible subsamples in the size of 32 in the lists.
What is the best way to do it in python?
You can use the combinations
method of itertools
.
Just you can change items
data and the number of count in combinations
method from 2
to 32
.
Please refer the following sample code:
from itertools import combinations
items_a = ['a', 'b', 'c']
items_b = ['1', '2', '3', '4', '5']
items = items_a + items_b
print(list(combinations(items_a, 2)))
print(list(combinations(items_b, 2)))
The result.
[('a', 'b'), ('a', 'c'), ('b', 'c')]
[('1', '2'), ('1', '3'), ('1', '4'), ('1', '5'), ('2', '3'), ('2', '4'), ('2', '5'), ('3', '4'), ('3', '5'), ('4', '5')]
You don't want to do that.
You have two lists of size 48 and 68. You want size 32 subsets of each.
There are 2 e 12 and 2 e 19 subsets of each. Multiplying then you get 4 e 31. That's a very big number.
So here's a rule of thumb. 10 ^ 9 is roughly the number of operations per second. 10 ^ 16 is 1 year... You don't want to think about ^ 31.
Let's put it this way. The hashrate of the entire bitcoin network is about 70, 000, 000 trillion hashes per second. Or 2.2 e 27 per year. That's still short a few zeros.
Change your algorithm.