Filter out the results from itertools.product

Viewed 14

I am new to python

I am trying to find different combinations of 7 vectors, each vector has about 400 items using itertools.product function.

It's quite impossible to get the results of such a calculation, but actually, I don't need all the results. I want only to get the results that have a certain sum value.

I tried to filter out the results by if function but still I have to run all the process to do this, can i directly filter out only results which full fill certain sum ?

My code is like this

Result=itertools.product(Hop01,Hop02,Hop03,Hop04,Hop05,Hop06,Hop07)
Weight=147324.34
Loadings=[]
for i in list(Result):
    if ((sum (i)<1.01*Weight) and (sum (i)>0.99*Weight)):
        Loadings.append(i)
        print(i)

Thanks

1 Answers

I figured out how to do this

I used

Loadings=[]
for I in itertools.product(Hop01,Hop02,Hop03,Hop04,Hop05,Hop06,Hop07):
    if sum (i)==(anyvalue):
        Loadings.append(i)
Related