In my calculation I had to go over non-zero elements of a 3 dimensional array (label). Instead of making 3 loops over each index of the array (which would be inefficient), I ended up doing something like this:
Is there a way to get rid of this loop as well, by vectorizing, and make this even more efficient? I tried stuff like:
But that doesn't give a correct result.
To further clarify what I need, I will give an example:
Now I want to count the different values of label_lin in clusters_size (this is what the for loop does), so that:
If I do something like:
I will instead get:
Which is obviously incorrect.