美文网首页我爱编程
numpy中argsort函数用法

numpy中argsort函数用法

作者: NILSTARK | 来源:发表于2016-07-21 21:27 被阅读582次

numpy.argsort(a, axis=-1, kind='quicksort', order=None)

Returns the indices that would sort an array.
Perform an indirect sort along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape as a that index data along the given axis in sorted order.

Parameters:
a : array_like
Array to sort.

axis : int or None, optional
Axis along which to sort. The default is -1 (the last axis). If None, the flattened array is used.

kind : {‘quicksort’, ‘mergesort’, ‘heapsort’}, optional
Sorting algorithm.

order : str or list of str, optional
When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. A single field can be specified as a string, and not all fields need be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties.

Returns:
index_array : ndarray, int
Array of indices that sort a along the specified axis. If a is one-dimensional, a[index_array] yields a sorted a.

例1:

x = np.array([3, 1, 2])
np.argsort(x) #按升序排列array([1, 2, 0])
np.argsort(-x) #按降序排列array([0, 2, 1])
x[np.argsort(x)] #通过索引值排序后的数组array([1, 2, 3])
x[np.argsort(-x)]array([3, 2, 1])
另一种方式实现按降序排序:
a = x[np.argsort(x)]
aarray([1, 2, 3])
a[::-1]array([3, 2, 1])

相关文章

  • numpy中argsort函数用法

    numpy.argsort(a, axis=-1, kind='quicksort', order=None) R...

  • numpy运算

    numpy的与运算 numpy 中 argsort() numpy 中的布尔索引

  • python中argsort函数用法

    argsort()函数是将x中的元素从小到大排列,提取其对应的index(索引),然后输出到y。 具体可以看如下的例子

  • python实现K近邻算法

    * 关于函数numpy.tile()的用法,可以参考:Numpy中tile()函数简单理解

  • Python中的相关排序方法

    在接触到numpy中的argsort()方法时,不太能理解其用法,所以搜索了一下,并对Python中的sort,s...

  • 一文详解numpy中np.nonzero()函数

    一文详解numpy中np.nonzero()函数Numpy中ndim、shape、dtype、astype的用法

  • python

    1.文件操作python3中不支持file,应该使用open numpy库argsort()函数最开始一直没搞懂这...

  • python numpy-argsort函数

    文档说明(装逼用) 只有第一个参数(输入数组)是必选,都是可选的(optional),它们的默认值已在函数定义中给...

  • [numpy]argsort

    可以根据值排序直接得到下标的顺序

  • np.argsort()函数用法

    在MNIST训练程序中,用np.argsort()函数来找到最大值的位置。使用范例如下:

网友评论

    本文标题:numpy中argsort函数用法

    本文链接:https://www.haomeiwen.com/subject/psobjttx.html