array([[ 0. , 0.04],
[ 0. , 0.1 ],
[ 0. , 0.2 ],
[ 0. , 0.4 ],
[ 0.27, 1. ],
[ 0.3 , 1. ]])
How to sort the array by the second column in descend order in an simple way ? The result's shape is also (6,2).
如何以简单的方式按降序排列第二列的数组?结果的形状也是(6,2)。
1 个解决方案
#1
1
Get argsort
indices for the second column, flip them and index into rows -
获取第二列的argsort索引,翻转它们并将其索引到行中 -
a[a[:,1].argsort()[::-1]]
Alternatively, get argsort
indices on negated version and index into rows -
或者,获取否定版本的argsort索引并将索引转换为行 -
a[(-a[:,1]).argsort()]
#1
1
Get argsort
indices for the second column, flip them and index into rows -
获取第二列的argsort索引,翻转它们并将其索引到行中 -
a[a[:,1].argsort()[::-1]]
Alternatively, get argsort
indices on negated version and index into rows -
或者,获取否定版本的argsort索引并将索引转换为行 -
a[(-a[:,1]).argsort()]