Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

index of sorted list python

vals = numpy.array([2,3,1,4,5])
sort_index = numpy.argsort(vals)

>>> sort_index
array([2, 0, 1, 3, 4])
Comment

How to sort and get index of sorted list in python

import numpy
# example list : [9, 3, 1, 5, 88, 22, 99] 
# make the list
my_list = numpy.array([9, 3, 1, 5, 88, 22, 99])

# for increasing order
# indexing 
index=numpy.argsort(my_list)

# sorting 
inc_list = sorted(my_list, reverse=False) 

print(inc_list,index)


# for decreasing order
# indexing 
index=numpy.argsort(-my_list)

# sorting 
dec_list = sorted(my_list, reverse=True) 

print(dec_list,index)
Comment

PREVIOUS NEXT
Code Example
Python :: selenium python chrome path 
Python :: python previous answer 
Python :: sorting pandas dataframe like excel 
Python :: random py 
Python :: dataframe split column 
Python :: python version check 
Python :: all alphabets 
Python :: pillow create image 
Python :: text to pandas 
Python :: python remove a key from a dictionary 
Python :: all possible combinations of parameters 
Python :: ready command discord.py 
Python :: numpy set_printoptions 
Python :: how to install python 2 
Python :: flask debug 
Python :: set text and background color in pandas table 
Python :: read text file in python 
Python :: python tkinter quit button 
Python :: createview 
Python :: get string between two characters python 
Python :: numpy arrays equality 
Python :: python clear screen windows and linux 
Python :: how to get current date in python 
Python :: python print unicode character 
Python :: open text with utf-8 
Python :: nan float python 
Python :: plot distribution seaborn 
Python :: python enumerate() function 
Python :: python check string case insensitive 
Python :: python 1 to 01 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =