title: Fast and efficient way to subtract arrays
body: <p>I have a large stack of images and I need to subtract, from each image, the background. The initial stack is five-dimensional and the image to subtract is two-dimensional. Subtraction works well using nested loops, but not when I switch to a <code>[:,:]</code> notation. Do you have any suggestion on how to fix this?</p>
  
  <p>In other words, this works</p>
  
  <pre><code>for aa in range(B.shape[0]):
      for bb in range(B.shape[1]):
          A_clean[i,j,k,aa,bb] = A[i,j,k,aa,bb] - B[aa,bb]
  </code></pre>
  
  <p>And this, which I would prefer to use because it is much faster, doesn't </p>
  
  <pre><code>A_clean[i,j,k,:,:] = A[i,j,k,:,:] - B[:,:]
  </code></pre>
  
  <p><code>A</code>, <code>A_clean</code> and <code>B</code> are all numpy arrays.</p>