0
如何使用python并行修改复数数组的不同部分? 这个问题似乎给出了具有实系数的numpy数组的答案:Is shared readonly data copied to different processes for Python multiprocessing?,但不适用于复系数。如何使用python并行修改复数数组的不同部分?
如何使用python并行修改复数数组的不同部分? 这个问题似乎给出了具有实系数的numpy数组的答案:Is shared readonly data copied to different processes for Python multiprocessing?,但不适用于复系数。如何使用python并行修改复数数组的不同部分?
您需要查看包含两次浮子数量漂浮为复数阵列:
>>> shared_array_base = multiprocessing.Array(ctypes.c_double, 3*3*2)
>>> shared_array = np.ctypeslib.as_array(shared_array_base.get_obj())
>>> shared_array = shared_array.view(np.complex128).reshape(3, 3)
复数格式为[RE0,IM0,RE1,IM1,RE2,IM2,...] :
>>> shared_array[1,1] = 1+2j
>>> shared_array.base
array([ 0., 0., 0., 0., 0., 0., 0., 0., 1., 2., 0., 0., 0.,
0., 0., 0., 0., 0.])
>>> shared_array.base.base
<multiprocessing.sharedctypes.c_double_Array_18 object at 0x7f7c1b5d1f80>