如何将两个 for 循环变成一个循环,以便可以使用 joblib?
How can I turn two for loops into one so that joblib can be used?
func
是一个复杂的函数。
我有两个for循环,如何将two
for循环变成one
以便可以使用joblib
?
代码如下:
def func(a, b):
print(a, b)
s1 = range(4)
d2 = range(5)
for s in s1:
for d in d2:
func(s, d)
I have two for loops, how can I turn two for loops into one so that joblib can be used?
您可以使用 itertools
模块组合迭代器,将多个循环“合并”为一个循环。
from itertools import product
s1 = range(4)
d2 = range(5)
for i in product(s1, d2):
# i is know equivalent to your (s, d)
print(i)
func
是一个复杂的函数。
我有两个for循环,如何将two
for循环变成one
以便可以使用joblib
?
代码如下:
def func(a, b):
print(a, b)
s1 = range(4)
d2 = range(5)
for s in s1:
for d in d2:
func(s, d)
I have two for loops, how can I turn two for loops into one so that joblib can be used?
您可以使用 itertools
模块组合迭代器,将多个循环“合并”为一个循环。
from itertools import product
s1 = range(4)
d2 = range(5)
for i in product(s1, d2):
# i is know equivalent to your (s, d)
print(i)