Help me extend this solution for high dimensional matrices in Julia

https://stackoverflow.com/questions/62097898/extend-this-solution-for-high-dimensional-matrices-in-julia

Seems like the only reason it wouldn’t extend as written is the matrix transposes. If you know the behavior you want in higher dimensions, this should be simple enough. E.g. if always the first two dimensions should be swapped you could do the same thing with permutedims. Otherwise I think all those operations are legal on arbitrary arrays.

1 Like

I agree. Its because of the transpose. Can you please help me in it though. Its my second day at Julia and I am porting a code from Python to Julia looking for speed benefits.

What should be the behavior for higher dimensional arrays? My suggestion is to forget that you want a one-liner, and figure out what should happen in a 3D case (since right now that isn’t super well defined). Maybe do it in a for-loop with an if Matrix2[i, j] == 1 check to start out with, and then go back to the vector indexing once that’s sorted out?