Python:如何使用hstack / vstack更新multiprocessing.Array对象

时间:2016-09-05 23:11:49

标签: python arrays numpy multiprocessing

你如何hstack/vstack一个{n}的multiprocessing.Array对象 数组没有覆盖mp.Array对象。

import multiprocessing as mp
import numpy as np 

    def init(aa, vv):
        global a, v
        a = aa
        v = vv

    def worker(i):
        a[i] = v.value * i
        # this next line writes over the mp.Array object. 
        a    = np.vstack([a[:], np.array(range(N) , dtype=np.int64)])

if __name__ == "__main__":
        N = 5
        a = mp.Array('d', np.array(range(N) , dtype=np.int64))
        v = mp.Value('i', 3)
        p = mp.Pool(initializer=init, initargs=(a, v))
        p.map(worker, range(N))
        print(a[:])

0 个答案:

没有答案