There is an array as below;
JavaScript
x
13
13
1
x=np.array([ ['0', '0'],
2
['1', '1'],
3
['7', '10'],
4
['8', '11'],
5
[',', '2'],
6
['4', '3'],
7
['.', '4'],
8
['2', '5'],
9
['5', '6'],
10
['er014', '7'],
11
['ww', '8'],
12
['*', '9']])
13
I used the following codes to sort this array by the second column but without success. Is there anyone to help?
JavaScript
1
3
1
A= np.take(x, x[:, 1].argsort(), 0)
2
3
Advertisement
Answer
np.take(x, x[:, 1].astype(int).argsort(), 0)
You may just cast the values for sorting. The overall result of you np.take() will remain as strings.
JavaScript
1
13
13
1
array([['0', '0'],
2
['1', '1'],
3
[',', '2'],
4
['4', '3'],
5
['.', '4'],
6
['2', '5'],
7
['5', '6'],
8
['er014', '7'],
9
['ww', '8'],
10
['*', '9'],
11
['7', '10'],
12
['8', '11']], dtype='<U5')
13