title: Python Run function in parallel
body: <p>Is there a way to speed this up by running in parallel? The longest process time is scipy.ndimage.map_coordinates.</p>
  <pre><code>import multiprocessing
  import numpy as np
  import scipy.ndimage
  
  pool = multiprocessing.Pool()
  n=6
  x0=350
  y0=350
  r=150
  num=10000
  #z = np.gradient(sensor_dat, axis=1)
  z = np.random.randn(700,700)
  
  def func1(i):
      x1, y1 = x0 + r * np.cos(2 * np.pi * i / n), y0 + r * np.sin(2 * np.pi * i / n)
      x, y = np.linspace(x0, x1, num), np.linspace(y0, y1, num)
      zi = scipy.ndimage.map_coordinates(z, np.vstack((y, x)))
      return zi
  
  [func4(i) for i in range(36)]
  #pool.map(func1,range(36))
  
  </code></pre>
  <p>I tried from <a href="https://stackoverflow.com/questions/1704401/is-there-a-simple-process-based-parallel-map-for-python">Is there a simple process-based parallel map for python?</a> to use <code>pool.map(func1,range(36))</code> but got error <code>Can't pickle &lt;function func1 at 0x0000019408E6F438&gt;: attribute lookup func1 on __main__ failed</code></p>
  <p>I found <a href="https://stackoverflow.com/questions/62679777/how-to-accelerate-scipy-map-coordinates-for-multiple-interpolations">How to accelerate scipy.map_coordinates for multiple interpolations?</a> but dont think this is relevent as scipy.ndimage.map_coordinates is the majority of process time, but dont think it will speed up in my case.</p>