并行写入两个列表(Python)
我尝试并行化 Python 中的底部 for 循环,因为对于 for 循环中的每次迭代,当前迭代都独立于所有其他迭代。 我找到了包“joblib”,但找不到如何同时填充两个列表的解决方案。
我非常感谢您的帮助!
import numpy as np
np.random.seed(42)
matrix = np.random.randn(10,10)
list1 = []
list2 = []
for i in range(10):
row = matrix[i,:]
list1.append(np.min(row))
list2.append(np.max(row))
I try to parallelize the bottom for-loop in Python since for each iteration in the for-loop the current iteration is independent of all others.
I found the package "joblib" but couldn't find a solution for how to fill two lists at the same time.
I would highly appreciate your help!
import numpy as np
np.random.seed(42)
matrix = np.random.randn(10,10)
list1 = []
list2 = []
for i in range(10):
row = matrix[i,:]
list1.append(np.min(row))
list2.append(np.max(row))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论