0
爲了減少我的計算時間,在接下來的文章中,有人告訴我使用map with concurrent.futures。但我不能讀取結果,我得到「發電機對象映射在0x7f0ef48ff2d0」「...我怎麼能做到這一點?Python - 使用concurrent.futures閱讀地圖
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))
發電機懶惰iterables - 嘗試迭代它以'for'循環或使用'名單(發電機)做一個清單'(注意,您可能希望避免,除非你的列表需要 - 它使用更多的內存並增加預先計算數據所需的時間)。 –