0

In order to decrease the time of my calculations, in following post, someone told me to use map with concurrent.futures. But i can t read the results, i get "generator object map at 0x7f0ef48ff2d0>"...how can i do that?

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))
user3601754
  • 3,792
  • 11
  • 43
  • 77
  • 3
    Generators are lazy iterables - try iterating over it with a `for` loop or make a list using `list(generator)` (note your probably want to avoid making a list unless you need to - it uses more memory and increases the time required up-front to calculate the data). – Gareth Latty Apr 28 '15 at 13:41

1 Answers1

2

Calling map returns an iterator, it does not return result directly. Here's what you could do:

with concurrent.futures.ProcessPoolExecutor() as exc:
    for result in exc.map(f, arr):
        print(result)
laike9m
  • 18,344
  • 20
  • 107
  • 140