NumPy in the Argsort function usage, there is a need for friends to refer to the next.
Using Help in Python
>>> Import NumPy
>>> Help (Numpy.argsort)
Help on function Argsort in module numpy.core.fromnumeric:
Argsort (A, axis=-1, kind= ' quicksort ', Order=none)
Returns the indices that would sort an array.
Perform an indirect sort along the given axis using the algorithm specified
By the ' kind ' keyword. It returns an array of indices of the same shape as
' A ' that's index data along the given axis in sorted order.
As you can see, the Argsort function returns the index value of the array value from small to large
Examples
--------
One dimensional array: single-dimensional arrays
>>> x = Np.array ([3, 1, 2])
>>> Np.argsort (x)
Array ([1, 2, 0])
Two-dimensional array: two-dimensional arrays
>>> x = Np.array ([[0, 3], [2, 2]])
>>> x
Array ([[0, 3],
[2, 2]])
>>> np.argsort (x, axis=0) #按列排序
Array ([[0, 1],
[1, 0]])
>>> np.argsort (x, Axis=1) #按行排序
Array ([[0, 1],
[0, 1]])
#######################################
Example 1:
>>> x = Np.array ([3, 1, 2])
>>> np.argsort (x) #按升序排列
Array ([1, 2, 0])
>>> Np.argsort (-X) #按降序排列
Array ([0, 2, 1])
>>> X[np.argsort (x)] #通过索引值排序后的数组
Array ([1, 2, 3])
>>> X[np.argsort (-X)]
Array ([3, 2, 1])
Another way to achieve this is to sort in descending order:
>>> A = X[np.argsort (x)]
>>> A
Array ([1, 2, 3])
>>> A[::-1]
Array ([3, 2, 1])
In addition to the sort, there are two commonly used functions sort and sorted, see the details: Http://maoersong.blog.163.com/blog/static/171557351201424105925681/?newFollowBlog
Python--argsort function