I wrote a code in python that takes a numpy matrix as input and returns a list of indices grouped by the corresponding values (i.e. output[3] returns all indices with value of 3). However, I lack the knowledge of writing vectorized code and had to do it using ndenumerate. This operation only took about 9 seconds which is too slow.
The second idea that I had was using numpy.nonzero as follows:
for i in range(1, max_value):
current_array = np.nonzero(input == i)
# save in an array
This took 5.5 seconds and so it was a good improvement but still slow. Any way to do it without loops or optimized way to get the pairs of indices per value?