你如何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[:])