我想使用“ThreadPoolExecutor”或“ProcessPoolExecutor”,这样我的代码运行得更快(我使用的是Windows)。我有一个包含4个变量的for循环,我希望在相同的范围内运行它们,并使用所有可能的组合,因此我使用的是“itertools:
from itertools import product #Multiple loops
p=range(1,200,10)
No=4
for op0,op1,op2,op3 in product(p, repeat=No):
op=[op0,op1,op2,op3]
o=np.empty(No)
for i in range(0,No):
o[i]=0.1*op[i]
然后,我想执行以下操作,以便我的代码以多线程方式运行:
from itertools import product #Multiple loops
import concurrent.futures #Multithreading/processing
p=range(1,200,10)
No=4
with concurrent.futures.ThreadPoolExecutor() as executor:
for op0,op1,op2,op3 in executor.product(p, repeat=No):
op=[op0,op1,op2,op3]
o=np.empty(No)
for i in range(0,No):
o[i]=0.1*op[i]
我得到错误“'ThreadPoolExecutor'对象没有属性'product'”,但是有没有类似的方法
提前感谢:)
目前没有回答
相关问题 更多 >
编程相关推荐