0
我有一個包含對象列表的對象。我想這樣做:關於對象參數的多處理映射
def compute_weight(particle, data):
particle.weight = run_computation(data)
class SomeClass:
def __init__(self):
self.particles = [obj1, obj2, etc]
def run(self, data):
[compute_weight(particle, data) for p in self.particles]
這些可以獨立運行,但我需要self.particles包含每個更新的顆粒。目前,我有一招推兩個參數到pool.map功能
# equivalent function as above
pool.map(compute_weight_star, itertools.izip(self.particles,
itertools.repeat(data)))
但每個particle.weight似乎並沒有被更新。我究竟做錯了什麼?