0

为了减少我的计算时间,在下面的帖子中,有人告诉我将 map 与 concurrent.futures 一起使用。但我无法读取结果,我得到“0x7f0ef48ff2d0> 处的生成器对象映射”......我该怎么做?

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))
4

1 回答 1

2

调用map返回一个迭代器,它不直接返回结果。这是你可以做的:

with concurrent.futures.ProcessPoolExecutor() as exc:
    for result in exc.map(f, arr):
        print(result)
于 2015-05-06T05:36:04.610 回答