, . [2,1,0,3] result :
In [37]: result[[2,1,0,3],:]
Out[37]:
array([[0, 1, 0, 0, 1],
[1, 0, 0, 0, 0],
[0, 1, 1, 0, 1],
[0, 1, 0, 1, 0]])
In [38]: result[[2,1,0,3],:4]==data
Out[38]:
array([[ True, True, True, True],
[ True, True, True, True],
[ True, True, True, True],
[ True, True, True, True]], dtype=bool)
, argsort sort .
np.lexsort :
In [54]: data[np.lexsort(data.T),:]
Out[54]:
array([[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 1, 0, 1]])
In [55]: result[np.lexsort(result[:,:-1].T),:]
Out[55]:
array([[1, 0, 0, 0, 0],
[0, 1, 0, 0, 1],
[0, 1, 1, 0, 1],
[0, 1, 0, 1, 0]])
, . lexsort, , .
:
In [66]: i=np.lexsort(data.T)
In [67]: j=np.lexsort(result[:,:-1].T)
In [68]: j[i]
Out[68]: array([2, 1, 0, 3], dtype=int64)
In [69]: result[j[i],:]
Out[69]:
array([[0, 1, 0, 0, 1],
[1, 0, 0, 0, 0],
[0, 1, 1, 0, 1],
[0, 1, 0, 1, 0]])
. . .