I am trying to convert a numpy A array to B without using a loop.
A=np.array([[1,2,3],
[1,3,0],
[2,0,0]])
B=np.array([[1,2,3],
[1,0,3],
[0,2,0]])
Therefore, in each row, I want to change the order of the records, using their value as an index. (i.e., in line 2,, [1,3,0]1 is the first entry, 3 is the third entry, and 0 will be populated as the second entry to make it [1,0,3].
I can do this on a single line so that I can iterate over the array, but I wanted to see if there is a way to do this without a loop. I know that a loop will not matter for small arrays like this, but I'm afraid the loop will create a bottleneck when doing this on large arrays (1 m, 1 m).
Thank!