title: Find multiple maximum values in a 2d array fast
body: <p>The situation is as follows:</p>
  
  <p>I have a 2D numpy array. Its shape is (1002, 1004). Each element contains a value between 0 and Inf. What I now want to do is determine the first 1000 maximum values and store the corresponding indices in to a list named x and a list named y. This is because I want to plot the maximum values and the indices actually correspond to real time x and y position of the value.</p>
  
  <p>What I have so far is:</p>
  
  <pre><code>x = numpy.zeros(500)
  y = numpy.zeros(500)
  
  for idx in range(500):
      x[idx] = numpy.unravel_index(full.argmax(), full.shape)[0]
      y[idx] = numpy.unravel_index(full.argmax(), full.shape)[1]
      full[full == full.max()] = 0.
  
  print os.times()
  </code></pre>
  
  <p>Here full is my 2D numpy array. As can be seen from the for loop, I only determine the first 500 maximum values at the moment. This however already takes about 5 s. For the first 1000 maximum values, the user time should actually be around 0.5 s. I've noticed that a very time consuming part is setting the previous maximum value to 0 each time. How can I speed things up?</p>
  
  <p>Thank you so much!</p>