title: How can I subtract all elements of an array from all elements in another in Python?
body: <p>I need to subtract a number from an array x1 from all the numbers in an array x2 and check if the absolute value of the result is less than 0.01, if it is then append x1 to a new array. I then need this to repeat for all the elements in the array x1.</p>
  
  <p>Doing this is going to require 25 billion calculations as both arrays are long (50000 and 500000 elements), so I'd prefer to minimize the amount of processing required.</p>
  
  <p>Thank you!</p>
  
  <pre><code>b = np.zeros(len(a), 1)               #a is a list of numbers 48555 elements long
  b[:,0] = a[:,0]
  
  e = np.zeros(len(d), 1)               #d is a list of numbers 531261 elements long
  e[:,0] = d[:,0]
  
  h = np.zeros(len(len(a)*len(d),1)     #h needs to be an array of length a*d
  for i in e, j in b,
  if abs(i-j)&lt;=0.01,
  h.append(i)
  
  print h
  </code></pre>
  
  <p>I haven't used code much before so I'm still making fairly basic errors with Python.</p>