如何使用python来对二维数组进行复合排序?

如题所述

# ä¾‹å­
import numpy as np

data = np.array([[1,2,3,4,5],
                [1,2,3,6,7],
                [2,3,4,5,7],
                [3,4,5,6,7],
                [4,5,6,7,8]])
sorted_cols = []
for col_no in range(data.shape[1]):
    sorted_cols.append(data[np.argsort(data[:,col_no])][:,col_no])
sorted_data = np.column_stack(sorted_cols)
温馨提示:答案为网友推荐,仅供参考
相似回答