title: Affinity Matrix Calculation using Numpy
body: <p>I am trying to create an affinity matrix for an image. I am trying to use simple pixel value differences for now, my image is 84x84, flattened it is a vector of size 7056,  which gives me affinity matrix A of size 7056x7056. To fill in the values of the affinity matrix, I started with the obvious the method:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  
  Img = plt.imread("twoObj.bmp")
  Img2 = Img.flatten()
  (n,) = Img2.shape
  print n
  A = np.zeros((n,n))
  for i in range(n):
      for j in range(n):
          A[i,j] = np.abs(Img2[i] - Img2[j])
  </code></pre>
  
  <p>but this was taking too long to execute. Is there any built-in way in Numpy, or available libraries to run this faster? </p>