title: Moving an Image Around a Grid
body: <p>I would like to know of a very efficient to do the following in Python.</p>
  
  <p>Suppose I've got an image of an object <strong>'D'</strong> which is my data, and a model that represents <strong>'M'</strong>. I've created a very basic example below, where the Data is simply a circle. Imagine the Data is slightly shifted by <strong>3px in X and 2px in Y</strong> and my Model is initially set to be in the center. (In this example both the data and model are in the center) I'd like to be able to get the model, <strong>M</strong>, and shift it by a grid of say 5px x 5px (with 1px intervals) and at each iteration subtract it with the data to see which of the shifts gives me the least error.</p>
  
  <p>Thanks.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  dim = 512
  
  # Create the Data.
  xx, yy = np.mgrid[:dim, :dim]
  D = (xx - dim/2) ** 2 + (yy - dim/2) ** 2
  
  # Create the Model.
  M = D.copy()
  
  plt.imshow(D)
  plt.show()
  </code></pre>