Reputation: 973
I have a matrix with 10 columns of different types. I sorted them based on the alphanumeric column with :
data = np.sort(data, axis=0,order='AlphaNumColumn')
It didn't do the job right, i.e.
BFT_job10_q0
BFT_job13_q0
BFT_job13_q1
BFT_job1_q0
instead of :
BFT_job1_q0
BFT_job10_q0
BFT_job13_q0
BFT_job13_q1
Anything numpy could do about it?? Thanks!
Upvotes: 1
Views: 2600
Reputation: 58985
The sorting order seems to be right. I would recommend you to review your numbering:
1 becomes 01
If you have to keep your numbering, you can also do:
key = lambda x: '.'.join(x.split('_')[1:3]).replace('job','').replace('q','')
a[np.argsort([float(key(i)) for i in a[:,0]])]
Where key()
will do the following:
key('BFT_job10_q0') --> 10.
key('BFT_job1_q0') --> 1.
key('BFT_job13_q1') --> 13.1
key('BFT_job13_q0') --> 13.
Upvotes: 3