title: Efficient way to subtract each element of list from itself in Python
body: <p>I want to subtract each element of a list from itself and produce a list of lists. e.g:</p>
  
  <pre><code>x = [1,2,3,4,5]
  
  # expect this 
  x_sub = [[0,1,2,3,4],
           [1,0,1,2,3],
           [2,1,0,1,2],
           [3,2,1,0,1],
           [4,3,2,1,0]]
  </code></pre>
  
  <p>In my case the list has 120,000 members so need something efficient. At the moment this is my code but it is incredibly slow.</p>
  
  <pre><code>import time
  import numpy as np
  
  data = np.random.randint(10, size=100000)
  allDiffs= []
  
  start = time.time()
  # Iterate over each centroid calculating the costs
  for i, x in enumerate(data):
  
      diff = [np.abs(data[i]-a) for a in data]
      allDiffs.append(diff)
  
  
  end = time.time()
  print(end-start)
  </code></pre>