【发布时间】:2019-10-02 04:00:48
【问题描述】:
我有以下 for 循环:
for j in range(len(list_list_int)):
arr_1_, arr_2_, arr_3_ = foo(bar, list_of_ints[j])
arr_1[j,:] = arr_1_.data.numpy()
arr_2[j,:] = arr_2_.data.numpy()
arr_3[j,:] = arr_3_.data.numpy()
我想用多处理申请foo,主要是因为它需要很长时间才能完成。我尝试用funcy's chunks 方法分批做:
for j in chunks(1000, list_list_int):
arr_1_, arr_2_, arr_3_ = foo(bar, list_of_ints[j])
arr_1[j,:] = arr_1_.data.numpy()
arr_2[j,:] = arr_2_.data.numpy()
arr_3[j,:] = arr_3_.data.numpy()
但是,我收到了list object cannot be interpreted as an integer。使用多处理应用 foo 的正确方法是什么?
【问题讨论】:
-
根据文档和我自己的测试,您所称的方式 应该 工作。不知道为什么不这样做,但您可以尝试明确指定一个步骤(如果您想要默认行为,该步骤应该与第一个参数具有相同的值)。
-
是否有其他方法可以应用该功能? @马克
-
来自
for j in chunks(1000, list_list_int):,j不是整数,是list_list_int的子列表,所以,你需要再次迭代j。 i.stack.imgur.com/JXDmZ.png -
感谢@KingStone 的帮助,你能举个例子吗?
-
我用代码屏幕更新了我的评论。但是,块不能提高速度。 stackoverflow.com/questions/11515944 怎么样
标签: python-3.x numpy iteration batch-processing funcy