First off, I know there is a pretty easy way doing this using a for-loop, but this is a calculation that needs to be done a lot of times every second, and for-loops in python are just way too inefficient to do this. So I am looking for something in numpy that could fix this.
I have a 2D array(arr1) with values between 0 and 256 and a 1D array(arr2) that has the size 256 and contains information of how frequently a number in that 2D array is present. So for exemple if arr1[0, 0] = 1 and arr1[0, 1] = 1 and those are the only ones that have value 1, then arr2[1] = 2, because the value 1 exists twice in arr1.
What I want to do now, is mapping that frequency number onto arr1, so as in the previous exemple arr1[0,0] and arr1[0,1] would both become 2, because that's the frequency of their previous value.
In short this would look something like this, but obviously this can't just work outside a for-loop:
arr1[i,j] = arr2[arr1[i,j]]
Is there an easy, fast and efficient way to do this using numpy?