1、python的內建排序函數有 sort、sorted兩個
sort函數只定義在list中,sorted函數對於所有的可迭代序列都可以定義.
for example:
ls = list([5, 2, 3, 1, 4])
new_ls = sorted(ls)
/*或者使用ls.sort()即可,直接將ls改變*/
print(new_ls)
2、argsort()函數,是numpy庫中的函數,返回的是數組值從小到大的索引值
for example:
One dimensional array:一維數組
>>> x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])