I have an n*m array "a", and another 1D array "b", such as the following:
a = array([[ 51, 30, 20, 10],
[ 10, 32, 65, 77],
[ 15, 20, 77, 30]])
b = array([10, 15, 20, 30, 32, 51, 65, 77])
I would like to replace all elements in "a" with the corresponding index of "b" where that element lies. In the case above, I would like the output to be:
a = array([[ 5, 3, 2, 0],
[ 0, 4, 6, 7],
[ 1, 2, 7, 3]])
Please note, in real application my arrays are large, over 30k elements and several thousands of them. I have tried for loops but these take a long time to compute. I have also tried similar iterative methods, and using list.index() to grab the indices but this also takes too much time.
Can anyone help me in identifying first the indices of "b" for the elements of "a" which appear in "b", and then constructing the updated "a" array?
Thank you.