What is the most efficient way to sort two numpy matrices in parallel, row by row? A toy example:
sort this alpha:
a = [['c', 'b', 'e', 'd'],
['a', 'd', 'b', 'e']]
then, sort this in parallel to a:
b = [['1', '2', '3', '4'],
['2', '1', '4', '3']]
Result after sorting:
a = [['b', 'c', 'd', 'e'],
['a', 'b', 'd', 'e']]
b = [['2', '1', '4', '3'],
['2', '4', '1', '3']]
In my real case, a
and b
are large, 2D matrices of the same size.
If I use idx = a.argsort()
, I obtain the indices to sort each row of a. Can these be applied to b in one step? b = b[idx]
is not working.