문제

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!

도움이 되었습니까?

해결책

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.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top