title: How to return indices from sorting a 2d numpy array row-by-row?
body: <p>Input: A 2D numpy array</p>
  
  <p>Output: An array of indices that will sort the array row by row (or column by column)</p>
  
  <p>E.g.: Say the function is get_sorted_indices(array, axis=0)</p>
  
  <pre><code>a = np.array([[1,2,3,4,5]
               ,[2,3,4,5,6]
               ,[1,2,3,4,5]
               ,[2,3,4,6,6]
               ,[2,3,4,5,6]])
  
  ind = get_sorted_indices(a, axis=0)
  </code></pre>
  
  <p>Then we will get</p>
  
  <pre><code>&gt;&gt;&gt; ind 
  [0, 2, 1, 4, 3]
  &gt;&gt;&gt; a[ind]   # should be equals to a.sort(axis = 0)
  array([[1, 2, 3, 4, 5],
         [1, 2, 3, 4, 5],
         [2, 3, 4, 5, 6],
         [2, 3, 4, 5, 6],
         [2, 3, 4, 6, 6]])
  &gt;&gt;&gt; a.sort(axis=0) 
  array([[1, 2, 3, 4, 5],
         [1, 2, 3, 4, 5],
         [2, 3, 4, 5, 6],
         [2, 3, 4, 5, 6],
         [2, 3, 4, 6, 6]])
  </code></pre>
  
  <p>I've looked at argsort but I don't understand its output and reading the documentation doesn't help:</p>
  
  <pre><code>&gt;&gt;&gt; a.argsort() 
  array([[0, 1, 2, 3, 4],
         [0, 1, 2, 3, 4],
         [0, 1, 2, 3, 4],
         [0, 1, 2, 3, 4],
         [0, 1, 2, 3, 4]])
  
  &gt;&gt;&gt; a.argsort(axis=0) 
  array([[0, 0, 0, 0, 0],
         [2, 2, 2, 2, 2],
         [1, 1, 1, 1, 1],
         [3, 3, 3, 4, 3],
         [4, 4, 4, 3, 4]])
  
  </code></pre>
  
  <p>I can do this manually but I think I'm misunderstanding argsort or I'm missing something from numpy. 
  Is there a standard way to do this or I have no choice but to do this manually?</p>