R-order in python

Any ideas what is equivalent to python for R order?

order(c(10,2,-1, 20), decreasing = F) 
# 3 2 1 4
+4
source share
2 answers

Numpy has a function called argsort

import numpy as np
lst = [10,2,-1,20]
np.argsort(lst)
# array([2, 1, 0, 3]) 

Note that the pit list index starts at 0, starting at 1 in R.

+5
source

it numpy.argsort()

import numpy
a = numpy.array([10,2,-1, 20])
a.argsort()

# array([2, 1, 0, 3])

and if you want to study the parameter decreasing = T. You can try,

(-a).argsort()

#array([3, 0, 1, 2])
+2
source

Source: https://habr.com/ru/post/1653978/


All Articles