0

I have three lists and want to call a function which takes 3 arguments with all possible combinations of values of that 3 lists.

And if a condition is met, print the 3 values of the combination.

What is the fastest and best way to do that?

Here are my three lists:

a = np.linspace(0.01,constants.pi/2,50)  
b = np.arange(20,62,2)       
c = np.arange(0.3,1.5,0.1)

And I want to call a function let's say testAllCombination(a[i],b[j],c[k]) in each iteration, and if a the value returned is > 0, print the 3 values a[i], b[j] and c[k]. Is it possible to do this in a simple way?

ZelelB
  • 1,836
  • 7
  • 45
  • 71

2 Answers2

0

It seems you need the Cartesian product of your lists.

import itertools
list(itertools.product(a,b,c))

Note that this operation results in 50*21*12=12600 triples of items from a,b,c.

sentence
  • 8,213
  • 4
  • 31
  • 40
0

if the position is fixed to (a,b,c), you may consider simple loop. Otherwise if you need to change to other combinations like (b,c,a), (c,b,a)... use itertools

a = np.linspace(0.01,3.14/2,50)  
b = np.arange(20,62,2)       
c = np.arange(0.3,1.5,0.1)

myCombination=[]

for i in a:
    for j in b:
        for k in c:
            myCombination.append((i,j,k))

print(myCombination)
for item in myCombination:
    testCondition(item)

https://docs.python.org/2/library/itertools.html

Rebin
  • 516
  • 1
  • 6
  • 16