numpy - argsort

1. 函数原型

argsort(array, axis=1, kind='quicksort', order=None)

返回排序数组的索引,使用指定排序算法沿给定轴进行间接排序。返回一个与给定数组array相同的索引数组,axis=1, 0;同时可以在array变为array添加‘-’号来表示降序排列。


2. 应用

2.1 一维数组排序

# -*- coding: utf-8 -*-
import numpy as np

A = np.array([2, 1, 5, 7])

# 升序, index_A = [1, 0, 2, 3]
index_A = np.argsort(A)

# 降序, index_A = [3, 2, 0, 1]
index_A = np.argsort(-A)

2.2 二维数组排序

# -*- coding: utf-8 -*-
import numpy as np

A = np.array([[2, 1, 5, 7], [1, 8, 3, 5]])

index_A = np.argsort(A, axis=1)
index_A = np.argsort(A, axis=0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值