numpy srgsort,[:::-1]切片与[:-1]

一:np.agsort()对array排序,

https://docs.scipy.org/doc/numpy/reference/generated/numpy.argsort.html

1:1维数据

参考官方文档,返回了升序排列的索引

>>> x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])

2:2维数据

不加axis参数,默认按aixs=-1排序,2维情况默认按列排序,即每一行排完后有序

x = np.array([[0, 3,4], [2, 2,7]])

np.argsort(x)
Out[25]: 
array([[0, 1, 2],
       [0, 1, 2]], dtype=int64)

使用axis=0,按行排序,每一列有序;axis=1,按列排序,2维情况下等同不设置axis

np.argsort(x,axis=0)
Out[26]: 
array([[0, 1, 0],
       [1, 0, 1]], dtype=int64)
np.argsort(x,axis=1)
Out[27]: 
array([[0, 1, 2],
       [0,
  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值