为了减少计算的时间,在下面的文章中,有人告诉我在concurrent.futures中使用map。但是我无法读取结果,我得到了“0x7f0ef48ff2d0>中的生成器对象映射”...how,我能这样做吗?
import concurrent.futures
import numpy
def f(num):
return num * 2
arr = numpy.array(
[numpy.array([
numpy.array([1,2,3]),
numpy.array([4,5,6]),
numpy.array([7,8,9])]),
numpy.array([
numpy.array([1,2,3]),
numpy.array([4,5,6]),
numpy.array([7,8,9])])])
with concurrent.futures.ProcessPoolExecutor() as exc:
print(exc.map(f, arr))发布于 2015-05-06 05:36:04
调用map返回迭代器,它不会直接返回结果。以下是你可以做的:
with concurrent.futures.ProcessPoolExecutor() as exc:
for result in exc.map(f, arr):
print(result)https://stackoverflow.com/questions/29921201
复制相似问题