Numpy的argsort()方法

numpy.argsort(a, axis=-1, kind=None, 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.


    使用kind關鍵字指定的算法沿給定軸執行間接排序。它返回一個數組的索引相同的形狀作爲一個索引數據沿給定的軸排序。

—————————————————————————————————————————————

  • 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’, ‘stable’}, optional
    Sorting algorithm. The default is ‘quicksort’. Note that both ‘stable’ and ‘mergesort’ use timsort under the covers and, in general, the actual implementation will vary with data type. The ‘mergesort’ option is retained for backwards compatibility.


    默認是快速排序。注意,穩定和歸併排序都在幕後使用timsort,通常,實際實現會隨着數據類型的不同而有所不同。保留歸併排序選項是爲了向後兼容

    注:Changed in version 1.15.0.: The ‘stable’ option was added.

  • 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.


    當a是一個定義了字段的數組時,這個參數指定首先比較哪個字段,然後比較哪個字段,等等。可以將單個字段指定爲字符串,並且不需要指定所有字段,但仍將使用未指定的字段(按它們在dtype中出現的順序)來斷開連接

—————————————————————————————————————————————

  • 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. More generally, np.take_along_axis(a, index_array, axis=axis) always yields the sorted a, irrespective of dimensionality.


    將a沿指定軸排序的索引數組。如果a是一維的,則[index_array]產生一個排序後的a。take_along_axis(a, index_array, axis=axis)總是生成排序後的a,而不考慮維數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章