获取排序的Numpy数组的原始索引 [英] Get original indices of a sorted Numpy array

查看:170
本文介绍了获取排序的Numpy数组的原始索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个距离为a = np.array([20.5 ,5.3 ,60.7 ,3.0 ], 'double')的数组,我需要排序后的数组的索引(例如[3, 1, 0, 2],对于a.sort()). Numpy中有一个功能可以做到这一点吗?

I have an array of distances a = np.array([20.5 ,5.3 ,60.7 ,3.0 ], 'double') and I need the indices of the sorted array (for example [3, 1, 0, 2], for a.sort()). Is there a function in Numpy to do that?

推荐答案

是的,有x = numpy.argsort(a)函数或x = numpy.ndarray.argsort(a)方法.它完全符合您的要求.您也可以像在ndarray对象上那样,将argsort作为方法调用:a.argsort().

Yes, there's the x = numpy.argsort(a) function or x = numpy.ndarray.argsort(a) method. It does exactly what you're asking for. You can also call argsort as a method on an ndarray object like so: a.argsort().

以下是文档的链接: http ://docs.scipy.org/doc/numpy/reference/generation/numpy.argsort.html#numpy.argsort

这篇关于获取排序的Numpy数组的原始索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆