I am trying to transform transform a numpy array A into 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]])
So in each row, I want to reorder the entries using their value as the index. (i.e. in row 2, [1,3,0], 1 is the first entry, 3 is the third entry, and the 0 would fill in as the 2nd entry to make it [1,0,3].
I can do this for a single row so I could loop through the array, but I wanted to see if there was a way to do this without a loop. I know looping won't make a difference on small arrays like this, but I fear looping will create a bottleneck when doing this on large arrays (1m,1m).
Thank you!