Horje
numpy argsort Code Example
numpy argsort
# Python program explaining
# argpartition() function
   
import numpy as geek
  
# input array
in_arr = geek.array([ 2, 0,  1, 5, 4, 1, 9])
print ("Input unsorted array : ", in_arr) 
  
out_arr = geek.argsort(in_arr)
print ("Output sorted array indices : ", out_arr)
print("Output sorted array : ", in_arr[out_arr])
python argsort
def g(seq):
    # http://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python/3383106#3383106
    #lambda version by Tony Veijalainen
    return [x for x,y in sorted(enumerate(seq), key = lambda x: x[1])]
numpy argsort
x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])
Source: numpy.org
numpy argsort
ind = np.argsort(x, axis=0)  # sorts along first axis (down)
ind
array([[0, 1],
       [1, 0]])
np.take_along_axis(x, ind, axis=0)  # same as np.sort(x, axis=0)
array([[0, 2],
       [2, 3]])
Source: numpy.org
numpy argsort
x = np.array([[0, 3], [2, 2]])
x
array([[0, 3],
       [2, 2]])
Source: numpy.org




Python

Related
python script to execute shell azure cli commands in python Code Example python script to execute shell azure cli commands in python Code Example
single line return python Code Example single line return python Code Example
discord.py find user by name Code Example discord.py find user by name Code Example
how to slice a set in python Code Example how to slice a set in python Code Example
label with list comprehension python Code Example label with list comprehension python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7