Parallelizing four nested loops in Python

后端 未结 3 619
予麋鹿
予麋鹿 2020-12-28 09:40

I have a fairly straightforward nested for loop that iterates over four arrays:

for a in a_grid:
    for b in b_grid:
        for c in c_grid:
            fo         


        
3条回答
  •  长情又很酷
    2020-12-28 10:36

    If you use a tool that makes it easy to parallelize two nested loops, but not four, you can use itertools.product to reduce four nested for loops into two:

    from itertools import product
    
    for a, b in product(a_grid, b_grid):
        for c, d in product(c_grid, d_grid):
            do_some_stuff(a, b, c, d)
    

提交回复
热议问题