Python Numpy matrix.argsort()
在Numpy matrix.argmax()方法的帮助下,我们能够在给定的具有一个或多个维度的矩阵中找到排序的元素,并将返回排序元素的索引值。
语法: matrix.argsort()
返回:返回矩阵中排序元素的索引号
例子#1 :
在这个例子中,我们可以看到,在matrix.argsort()方法的帮助下,我们能够在一个给定的矩阵中找到排序的元素,并将输出作为排序数组的索引。
# import the important module in python
import numpy as np
# make a matrix with numpy
gfg = np.matrix('[1, -2, 3, -4]')
# applying matrix.argsort() method
geeks = gfg.argsort()
print(geeks)
输出:
[[3 1 0 2]]
例子#2 :
# import the important module in python
import numpy as np
# make a matrix with numpy
gfg = np.matrix('[-1, 2, 3; 4, -5, 6; 7, -8, 9]')
# applying matrix.argsort() method
geeks = gfg.argsort()
print(geeks)
输出:
[[0 1 2]
[1 0 2]
[1 0 2]]