[英]Is there a way to run two loops (for loops ,while loops,....) in the same time?
有没有办法在 Ppython 中同时运行两个循环(for 循环,while 循环,...)? 举一个简单的例子,我想并行地(同时)运行两个 for 循环,而不是线性地(一个接一个)。 如果可能的话,请告诉我这个脚本中的循环:
for x in range (0,10):
print('hello world')
for x in range(0,10 ):
print ('welcome to the world')
最简单的方法是使用 numba:
@jit(nopython=True, parallel=True)
def simulator(out):
# iterate loop in parallel
for i in prange(out.shape[0]):
print('hello world')
print('welcome to the world')
另一种方法是使用 asyncio,但处理起来更复杂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.