I have an N by 2 array like this one:
[[9 1]
[0 5]
[6 3]
[2 4]
[3 5]
[4 1]
[2 7]
[6 8]
[7 9]
[8 0]]
After I make a search in this matrix, I return some indices where the rows must be permuted.
In my case, I had w=[1 0 9 8 7].
I use this code to permute the 2 columns ONLY on selected rows.
for x in w:
self.nodes[x] = roll (self.nodes[x], 1)
The result is correct like this:
[[1 9] *
[5 0] *
[6 3]
[2 4]
[3 5]
[4 1]
[2 7]
[8 6] *
[9 7] *
[0 8]] *
The starred rows were correctly permuted.
I want to know if there is a ONE-LINER numpy expression that does all this trick.
The important fact here is the speed of the operation.