I've tried to use Ned Batchelder code to sort in human order a NumPy matrix, as it was proposed in this following post:
Sort numpy string array with negative numbers?
The code runs on a one-dimensional array, the command being:
print (sorted(a, key=natural_keys))
Now, my problem is that my data is a 10 column matrix and I want to sort it according to one column (let's say MyColumn). I can't find a way to modify the code to print the whole matrix sorted according to this very column. All I could come up with is this:
print (sorted(a['MyColumn'], key=natural_keys))
But, of course, only MyColumn shows up in the output, although it is correctly sorted...
Is there a way to print the whole Matrix?
Here is the command I used to load my array (I simplified my original imputfile to a 3 column array):
data = np.loadtxt(inputfile, dtype={'names': ('ID', 'MyColumn', 'length'),
'formats': ('int32', 'S40', 'int32')},skiprows=1, delimiter='\t')
ID MyColumn length
164967 BFT_job13_q1_type2 426
197388 BFT_job8_q0_type2 244
164967 BFT_job13_q0_type1 944
72406 BFT_job1_q0_type3 696
Here is what the output would ideally look like:
ID MyColumn length
72406 BFT_job1_q0_type3 696
197388 BFT_job8_q0_type2 244
164967 BFT_job13_q0_type1 944
164967 BFT_job13_q1_type2 426