title: Fast processing of numpy polyfit on 3d arrays?
body: <p>I have two numpy arrays with shapes of (400, 1000, 1000).
  I want to apply numpy.polyfit using the two arrays as input and fitting over axis 0. I have tried the following code, which could be very slow if I want to fit larger arrays. </p>
  
  <p><code>rows = arr1.shape[1]
   cols = arr1.shape[2]
   for i in range(rows):
      for j in range(cols):
          idx = np.isfinite(arr1[:, i, j]) &amp; np.isfinite(arr2[:, i, j])
          # Get slope
          slope = np.polyfit(arr1[:, i, j][idx], arr2[:, i, j][idx], 1)[0]
          ...</code></p>
  
  <p>Any idea how to speed this up?
  Thanks in advance!</p>