Is there any way to replace elements of a matrix with other elements from a dictionary in constant time without using loops. For example I have this initial matrix:
[[3 1 2]
[3 1 2]
[3 1 2]]
Then I have computed this dictionary {1: 5, 2: 6, 3: 4, 8: 9, 5: 1, 6: 2, 4: 3, 9: 8}
by some operations. What I want to do is change the initial matrix to:
[[4 5 6]
[4 5 6]
[4 5 6]]
As you see, the keys in the dictionary are the numbers in first matrix and values are the numbers in second matrix. I can do that by looping every cell but that would be slow. Is there any fast way to do that?