title: Numpy sort ndarray on multiple columns
body: <p>I get a <code>ndarray</code> reading it from a file, like this</p>
  
  <pre><code>my_data = np.genfromtxt(input_file, delimiter='\t', skip_header=0)
  </code></pre>
  
  <p>Example input (parsed)</p>
  
  <pre><code>[[   2.    1.    2.    0.]
   [   2.    2.  100.    0.]
   [   2.    3.  100.    0.]
   [   3.    1.    2.    0.]
   [   3.    2.    4.    0.]
   [   3.    3.    6.    0.]
   [   4.    1.    2.    0.]
   [   4.    2.    4.    0.]
   [   4.    3.    6.    0.]]
  </code></pre>
  
  <p>Longer <a href="http://pastebin.com/Zsv1HFVN" rel="noreferrer">example input</a> (unparsed).</p>
  
  <p>The first 2 columns are supposed to be <code>int</code>, while the last 2 columns are supposed to be <code>float</code>, but that's what I get. Suggestions are welcome.</p>
  
  <p>The main problem is, I'm trying to sort it, using Numpy, so that rows get ordered giving precedence to the numbers on second column first, and on the first column next.</p>
  
  <p>Example of desired output</p>
  
  <pre><code>[[   2.    1.    2.    0.]
   [   3.    1.    2.    0.]
   [   4.    1.    2.    0.]
   [   2.    2.  100.    0.]
   [   3.    2.    4.    0.]
   [   4.    2.    4.    0.]
   [   2.    3.  100.    0.]
   [   3.    3.    6.    0.]
   [   4.    3.    6.    0.]]
  </code></pre>
  
  <p>I'm aware of <a href="https://stackoverflow.com/a/2828121">this answer</a>, it works for sorting rows on a single column.</p>
  
  <p>I tried sorting on the second column, since the first one is already sorted, but it's not enough. On occasion, the first column gets reordered too, badly.</p>
  
  <pre><code>new_data = my_data[my_data[:, 1].argsort()]
  print(new_data)
  
  #output
  [[   2.    1.    2.    0.]
   [   4.    1.    2.    0.] #ouch
   [   3.    1.    2.    0.] #ouch
   [   2.    2.  100.    0.]
   [   3.    2.    4.    0.]
   [   4.    2.    4.    0.]
   [   2.    3.  100.    0.]
   [   3.    3.    6.    0.]
   [   4.    3.    6.    0.]]
  </code></pre>
  
  <p>I've also checked <a href="https://stackoverflow.com/q/19156472">this question</a></p>
  
  <p>The answer mentions</p>
  
  <blockquote>
    <p>The problem here is that np.lexsort or np.sort do not work on arrays of dtype object. To get around that problem, you could sort the rows_list before creating order_list:</p>
  </blockquote>
  
  <pre><code>import operator
  rows_list.sort(key=operator.itemgetter(0,1,2))
  </code></pre>
  
  <p>But I there is no <code>key</code> parameter in the <code>sort</code> function of type <code>ndarray</code>. And merging fields is not an alternative in my case.</p>
  
  <p>Also, I don't have a header, so, if I try to sort using the <code>order</code> parameter, I get an error.</p>
  
  <pre><code>ValueError: Cannot specify order when the array has no fields.
  </code></pre>
  
  <p>I'd rather sort in place or at least obtain a result of the same type <code>ndarray</code>. Then I want to save it to a file.</p>
  
  <p>How do I do this, without messing the datatypes?</p>