title: Sorting numpy array on multiple columns in Python
body: <p>I am trying to sort the following array on column1, then column2 and then column3</p>
  
  <pre><code>[['2008' '1' '23' 'AAPL' 'Buy' '100']
   ['2008' '1' '30' 'AAPL' 'Sell' '100']
   ['2008' '1' '23' 'GOOG' 'Buy' '100']
   ['2008' '1' '30' 'GOOG' 'Sell' '100']
   ['2008' '9' '8' 'GOOG' 'Buy' '100']
   ['2008' '9' '15' 'GOOG' 'Sell' '100']
   ['2008' '5' '1' 'XOM' 'Buy' '100']
   ['2008' '5' '8' 'XOM' 'Sell' '100']]
  </code></pre>
  
  <p>I used the following code:</p>
  
  <pre><code>    idx=np.lexsort((order_array[:,2],order_array[:,1],order_array[:,0]))
      order_array=order_array[idx]
  </code></pre>
  
  <p>The resultant array is</p>
  
  <pre><code>[['2008' '1' '23' 'AAPL' 'Buy' '100']
   ['2008' '1' '23' 'GOOG' 'Buy' '100']
   ['2008' '1' '30' 'AAPL' 'Sell' '100']
   ['2008' '1' '30' 'GOOG' 'Sell' '100']
   ['2008' '5' '1' 'XOM' 'Buy' '100']
   ['2008' '5' '8' 'XOM' 'Sell' '100']
   ['2008' '9' '15' 'GOOG' 'Sell' '100']
   ['2008' '9' '8' 'GOOG' 'Buy' '100']]
  </code></pre>
  
  <p>The problem is that the last two rows are wrong. The correct array should have the last row as the second last one. I have tried everything but am not able to understand why this is happening. Will appreciate some help.</p>
  
  <p>I am using the following code for obtaining order_array. </p>
  
  <pre><code> for i in ….
      x= ldt_timestamps[i] # this is a list of timestamps
      s_sym=……
      list=[int(x.year),int(x.month),int(x.day),s_sym,'Buy',100]   
      rows_list.append(list) 
  
   order_array=np.array(rows_list)
  </code></pre>