I would like to use a numpy array in shared memory for use with a multiprocessing module. The difficulty is using it as a numpy array, and not just as a ctypes array.
from multiprocessing import Process, Array import scipy def f(a): a[0] = -a[0] if __name__ == '__main__':
This produces output, for example:
Originally, the first two elements of arr = [0.3518653236697369, 0.517794725524976] Now, the first two elements of arr = [-0.3518653236697369, 0.517794725524976]
An array is accessed using the ctypes type, for example. arr[i] makes sense. However, it is not a numpy array, and I cannot perform operations such as -1*arr or arr.sum() . I assume that the solution would be to convert the ctypes array to a numpy array. However (apart from the fact that I cannot do this work), I do not believe that this will be general.
There seems to be a standard solution to what should be a common problem.
python numpy multiprocessing shared
Ian Langmore Oct 25 '11 at 19:34 2011-10-25 19:34
source share