title: Vectorize compressed sparse matrix from array in Python
body: <p>I am trying to apply graph theory methods to an image processing problem. I want to generate an adjacency matrix from an array containing the points I want to graph. I want to generate a complete graph of the points in the array. If I have N points in the array that I need to graph, I will need an NxN matrix. The weights should be the distances between the points, so this is the code that I have:</p>
  
  <pre><code>''' vertexarray is an array where the points that are to be 
      included in the complete graph are True and all others False.'''
  
  import numpy as np
  def array_to_complete_graph(vertexarray):
  
      vertcoords = np.transpose(np.where(vertexarray == True))
  
      cg_array = np.eye(len(vertcoords))
  
      for idx, vals in enumerate(vertcoords):
          x_val_1, y_val_1 = vals
          for jdx, wals in enumerate(vertcoords):
              x_diff = wals[0] - vals[0]
              y_diff = wals[1] - vals[1]
              cg_array[idx,jdx] = np.sqrt(x_diff**2 + y_diff**2)
      return cg_array
  </code></pre>
  
  <p>This works, of course, but my question is: can this same array be generated without the nested for loops?</p>