title: Find nth smallest element in numpy array
body: <p>I need to find just the the smallest nth element in a  1D <code>numpy.array</code>.</p>
  
  <p>For example:</p>
  
  <pre><code>a = np.array([90,10,30,40,80,70,20,50,60,0])
  </code></pre>
  
  <p>I want to get 5th smallest element, so my desired output is <code>40</code>.</p>
  
  <p>My current solution is this:</p>
  
  <pre><code>result = np.max(np.partition(a, 5)[:5])
  </code></pre>
  
  <p>However, finding 5 smallest elements and then taking the largest one them seems little clumsy to me. Is there a better way to do it? Am I missing a single function that would achieve my goal?</p>
  
  <p>There are questions with similar titles to this one, but I did not see anything that answered my question.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I should've mentioned it originally, but performance is very important for me; therefore, <code>heapq</code> solution though nice would not work for me.</p>
  
  <pre><code>import numpy as np
  import heapq
  
  def find_nth_smallest_old_way(a, n):
      return np.max(np.partition(a, n)[:n])
  
  # Solution suggested by Jaime and HYRY    
  def find_nth_smallest_proper_way(a, n):
      return np.partition(a, n-1)[n-1]
  
  def find_nth_smallest_heapq(a, n):
      return heapq.nsmallest(n, a)[-1]
  #    
  n_iterations = 10000
  
  a = np.arange(1000)
  np.random.shuffle(a)
  
  t1 = timeit('find_nth_smallest_old_way(a, 100)', 'from __main__ import find_nth_smallest_old_way, a', number = n_iterations)
  print 'time taken using partition old_way: {}'.format(t1)    
  t2 = timeit('find_nth_smallest_proper_way(a, 100)', 'from __main__ import find_nth_smallest_proper_way, a', number = n_iterations)
  print 'time taken using partition proper way: {}'.format(t2) 
  t3 = timeit('find_nth_smallest_heapq(a, 100)', 'from __main__ import find_nth_smallest_heapq, a', number = n_iterations)  
  print 'time taken using heapq : {}'.format(t3)
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>time taken using partition old_way: 0.255564928055
  time taken using partition proper way: 0.129678010941
  time taken using heapq : 7.81094002724
  </code></pre>