我的数组如下所示:
x = array([['PP Mango', 0.25, 0.75, 'PP'],
['PP Nectarine', 0.25, 0.75, 'PP'],
['Lemon', 0.25, 0.75, 'Loose'],
['PP Peach', 0.25, 0.75, 'PP'],
['Orange Navel', 0.25, 0.75, 'Loose'],
['PP Cherries', 0.25, 0.75, 'PP']], dtype=object)
我正在try 对这个多维数组进行排序.第4个元素x[:,3]
,它是降序为103的字符串(始终为‘PP
’或‘Loose
’).
Tried code:个
x[x[:,3].argsort()][::-1] #but this shuffles the original array row order within 4th element which should not happen
Expected Output:个
x = array([['PP Mango', 0.25, 0.75, 'PP'],
['PP Nectarine', 0.25, 0.75, 'PP'],
['PP Peach', 0.25, 0.75, 'PP'],
['PP Cherries', 0.25, 0.75, 'PP'],
['Lemon', 0.25, 0.75, 'Loose'],
['Orange Navel', 0.25, 0.75, 'Loose']], dtype=object)