title: Use numpy array in shared memory for multiprocessing
body: <p>I would like to use a numpy array in shared memory for use with the multiprocessing module.  The difficulty is using it like a numpy array, and not just as a ctypes array.</p>
  
  <pre><code>from multiprocessing import Process, Array
  import scipy
  
  def 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]
  </code></pre>
  
  <p>This produces output such as:</p>
  
  <pre><code>Originally, the first two elements of arr = [0.3518653236697369, 0.517794725524976]
  Now, the first two elements of arr = [-0.3518653236697369, 0.517794725524976]
  </code></pre>
  
  <p>The array can be accessed in a ctypes manner, e.g. <code>arr[i]</code> makes sense.  However, it is not a numpy array, and I cannot perform operations such as <code>-1*arr</code>, or <code>arr.sum()</code>.  I suppose a solution would be to convert the ctypes array into a numpy array.  However (besides not being able to make this work), I don't believe it would be shared anymore.</p>
  
  <p>It seems there would be a standard solution to what has to be a common problem.</p>