在共享内存中使用numpy数组进行多处理
from multiprocessing import Process, Arrayimport scipydef f(a):
a[0] = -a[0]if __name__ == '__main__':
# Create the array
N = int(10)
unshared_arr = scipy.rand(N)
arr = Array('d', unshared_arr)
print "Originally, the first two elements of arr = %s"%(arr[:2])
# Create, start, and finish the child processes
p = Process(target=f, args=(arr,))
p.start()
p.join()
# Printing out the changed values
print "Now, the first two elements of arr = %s"%arr[:2]Originally, the first two elements of arr = [0.3518653236697369, 0.517794725524976]Now, the first two elements of arr = [-0.3518653236697369, 0.517794725524976]
arr[i]-1*arrarr.sum()
郎朗坤
随时随地看视频慕课网APP
相关分类