ある行に着目して,ソートする方法なんかはぐぐればでてくるんです.これとか
でも,例えば
array([[1, 2, 1], [0, 2, 1], [0, 0, 0], [0, 1, 0], [2, 2, 2], [2, 1, 0], [1, 2, 2], [2, 2, 1]])
を
array([[0, 0, 0], [0, 1, 0], [0, 2, 1], [1, 2, 1], [1, 2, 2], [2, 1, 0], [2, 2, 1], [2, 2, 2]])
とするにはどうしたよいだろうか.結構簡単で,こうすればできる.
data = np.array([[1,2,1], [0,2,1], [0,0,0], [0,1,0], [2,2,2], [2,1,0], [1,2,2], [2,2,1]]) sort_keys = tuple(data[:, col] for col in range(data.shape[1]-1, -1, -1)) sort_indices = np.lexsort(sort_keys) sorted_data = data[sort_indices]