summarize
The argsort() function is in the module.
When sorting arrays in python, or getting the sort order, we often use the numpy package's argsort function to accomplish this.
The following figure shows the order in which the sorting in the array is obtained using python.
data=([1,2,3,4,5]) datasort=(data) datasort Out[39]: array([0, 1, 2, 3, 4], dtype=int64) data Out[40]: array([1, 2, 3, 4, 5]) datasort1=() datasort1 Out[42]: array([0, 1, 2, 3, 4], dtype=int64)
We can also see how to use it via help()
help() Help on function argsort in module : 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
If you want to sort by argsort you can use the slice implementation
data1=([1,3,4,56,2,0]) datasort=data1[()] datasort Out[48]: array([ 0, 1, 2, 3, 4, 56])
PS: argsort function in NumPy
Sort function, return array type
The argsort function returns the index of the element of the array value from smallest to largest.
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np inX = ([1,2,-1,3,4,7,8]) print inX print ()
summarize
The above is a small introduction to the use of the argsort function in the numpy package in python, I hope to help you, if you have any questions please leave me a message, I will reply to you in time. Here also thank you very much for your support of my website!