首页 > 编程知识 正文

python中range函数的用法,python中if语句的用法

时间:2023-05-03 20:00:46 阅读:269691 作者:176

python argsort()用法

先看一段程序:

def arg_sort(): import numpy as np x = np.array([1, 4, 5, 7, 3, 8, 0, -6]) a = sorted(x) b = x.argsort() print("x: ", x) print("a: ", a) print("b: ", b) print("b type: ", type(b))if __name__ == "__main__":arg_sort()

结果输出:

x: [ 1 4 5 7 3 8 0 -6]a: [-6, 0, 1, 3, 4, 5, 7, 8]b: [7 6 0 4 1 2 3 5]b type: <class 'numpy.ndarray'>

从结果上不难看出,argsort()先对原来的数组进行排序,然后输出排好序的元素在原来数组中的位置。输出类型与输入数组类型一致。

python中源码解释:供参考

def argsort(self, axis=-1, kind=None, order=None): # real signature unknown; restored from __doc__ """ a.argsort(axis=-1, kind=None, order=None) Returns the indices that would sort this array. Refer to `numpy.argsort` for full documentation. See Also -------- numpy.argsort : equivalent function """ pass

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。