本文簡要介紹 python 語言中  numpy.ndarray.sort  的用法。
- 用法:- ndarray.sort(axis=- 1, kind=None, order=None)
- 就地對數組進行排序。有關完整文檔,請參閱 - numpy.sort。- axis: 整數,可選
- 要排序的軸。默認為 -1,表示沿最後一個軸排序。 
- kind: {‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’},可選
- 排序算法。默認值為‘quicksort’。請注意,‘stable’ 和 ‘mergesort’ 都在後台使用 timsort,通常,實際實現會因數據類型而異。保留 ‘mergesort’ 選項是為了向後兼容。 
- order: str 或 str 列表,可選
- 當 a 是定義了字段的數組時,此參數指定首先比較哪些字段,第二個等。單個字段可以指定為字符串,不需要指定所有字段,但仍會使用未指定的字段,在他們在 dtype 中出現的順序,以打破關係。 
 
 - 參數:- 注意:- 有關不同排序算法的說明,請參閱 - numpy.sort。- 例子:- >>> a = np.array([[1,4], [3,1]]) >>> a.sort(axis=1) >>> a array([[1, 4], [1, 3]]) >>> a.sort(axis=0) >>> a array([[1, 3], [1, 4]])- 使用 order 關鍵字指定在對結構化數組進行排序時要使用的字段: - >>> a = np.array([('a', 2), ('c', 1)], dtype=[('x', 'S1'), ('y', int)]) >>> a.sort(order='y') >>> a array([(b'c', 1), (b'a', 2)], dtype=[('x', 'S1'), ('y', '<i8')])
相關用法
- Python numpy ndarray.setflags用法及代碼示例
- Python numpy ndarray.setfield用法及代碼示例
- Python numpy ndarray.strides用法及代碼示例
- Python numpy ndarray.size用法及代碼示例
- Python numpy ndarray.shape用法及代碼示例
- Python numpy ndarray.astype用法及代碼示例
- Python numpy ndarray.flat用法及代碼示例
- Python numpy ndarray.real用法及代碼示例
- Python numpy ndarray.itemset用法及代碼示例
- Python numpy ndarray.__class_getitem__用法及代碼示例
- Python numpy ndarray.partition用法及代碼示例
- Python numpy ndarray.transpose用法及代碼示例
- Python numpy ndarray.flatten用法及代碼示例
- Python numpy ndarray.resize用法及代碼示例
- Python numpy ndarray.dtype用法及代碼示例
- Python numpy ndarray.imag用法及代碼示例
- Python numpy ndarray.dot用法及代碼示例
- Python numpy ndarray.fill用法及代碼示例
- Python numpy ndarray.item用法及代碼示例
- Python numpy ndarray.nbytes用法及代碼示例
- Python numpy ndarray.tobytes用法及代碼示例
- Python numpy ndarray.copy用法及代碼示例
- Python numpy ndarray.ctypes用法及代碼示例
- Python numpy ndarray.view用法及代碼示例
- Python numpy ndarray.base用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.ndarray.sort。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
