numpy配列ソート

411 ワード

import numpy as np


data = np.array([[1,2,3,4,5],
                 [4,5,6,7,8],
                 [1,2,3,6,7],
                 [3,4,5,6,7],
                 [2,3,4,5,7]])
# col     
col = 0
idex=np.lexsort([1*data[:,col]])
# col2     
col2 = 3
idex2=np.lexsort([-1*data[:,col2]])

sorted_data = data[idex, :]
sorted_data2 = data[idex2, :]

print(sorted_data)
print(sorted_data2)