numpy.sort():此函數返回數組的排序副本。
參數:
- arr :要排序的數組。
axis :我們需要沿著其啟動數組的軸。
order :此參數指定要首先比較的字段。
kind :['quicksort'{default},'mergesort','heapsort']排序算法。
返回:
Sorted Array
# importing libraries
import numpy as np
# sort along the first axis
a = np.array([[12, 15], [10, 1]])
arr1 = np.sort(a, axis = 0)
print ("Along first axis : \n", arr1)
# sort along the last axis
a = np.array([[10, 15], [12, 1]])
arr2 = np.sort(a, axis = -1)
print ("\nAlong first axis : \n", arr2)
a = np.array([[12, 15], [10, 1]])
arr1 = np.sort(a, axis = None)
print ("\nAlong none axis : \n", arr1)
輸出:
Along first axis : [[10 1] [12 15]] Along first axis : [[10 15] [ 1 12]] Along none axis : [ 1 10 12 15]
相關用法
注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 numpy.sort() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。