title: Python/Numpy have I already written the swiftest code for large array?
body: <p>
  <strong>GOAL:</strong>
  I have a large 1d array (3000000+) of distances with many duplicate distances. I am trying to write the swiftest function that returns all distances that appear n times in the array. I have written a function in numpy but there is a bottleneck at one line in the code. Swift performance is an issue because the calculations are done in a for loop for 2400 different large distance arrays.</p>
  
  
  
  <pre><code>import numpy as np
  for t in range(0, 2400):
   a=np.random.randint(1000000000, 5000000000, 3000000)
   b=np.bincount(a,minlength=np.size(a))
   c=np.where(b == 3)[0] #SLOW STATEMENT/BOTTLENECK
   return c
  </code></pre>
  
  <p>
  <strong>EXPECTED RESULTS:</strong>
  Given a 1d array of distances [2000000000,3005670000,2000000000,12345667,4000789000,12345687,12345667,2000000000,12345667]
  I would expect back an array of [2000000000,12345667] when queried to return an array of all distances that appear 3 times in the main array.</p>
  
  <p>
  What should I do?</p>