Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. from collections import Counter
  2. from functools import partial
  3. from multiprocessing import Pool
  4.  
  5. output = {...}
  6. probabilities = {...}
  7. result = {...}
  8.  
  9. def reduce(probabilities, output, key_values):
  10.     ret = []
  11.  
  12.     key, values = key_values
  13.     for keys in output:
  14.         if any(keys >= value for value in values):
  15.             ret.append((keys, probabilities[key]))
  16.  
  17.     return ret
  18.  
  19. processes = Pool(4)
  20. tasks = processes.imap(partial(reduce, probabilities, output), result.items())
  21.  
  22. c = Counter()
  23. for task_result in tasks:
  24.     for key, value in task_result:
  25.         c[key] += value
  26.  
  27. print(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement