“Numpy Argsort” Kode Jawaban

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])
Tame Tarantula

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]])
Tame Tarantula

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])]
Erwin Smith

Numpy Argsort

x = np.array([[0, 3], [2, 2]])
x
array([[0, 3],
       [2, 2]])
Doubtful Dotterel

Numpy Argsort

x = np.array([3, 1, 2])
>>> np.argsort(x)
array([1, 2, 0])
Doubtful Dotterel

Jawaban yang mirip dengan “Numpy Argsort”

Pertanyaan yang mirip dengan “Numpy Argsort”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya