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])

相关文章:

  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2022-01-05
猜你喜欢
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2021-11-11
  • 2022-12-23
  • 2021-07-19
相关资源
相似解决方案