Hi all! I have been working on trying to understand the reverse function in Julia.

I have an array whose values I would like to flip horizontally. I specify in the function reverse(my_data, dims = 1) which does the job. However, What I am curious to know is what this transformation is called. I don’t want to just refer to it as “flipping the rows”.

Further, I tried looking at the underlying Julia code for it and understand that one counts the number of values and determines a midpoint to “flip” over top of as a sort of axis. Aside from that, I am confused by what the algorithm is actually doing.

Attached here are my notes on understanding how this works so far.

Perhaps the 2 by 2 matrix is a little small and a little misleading. One should think we have an array with n = 3 (for example) dimensions say A. Then reverse(A, dims = 1) should be thought of a new array B such that B[start,:,:] = A[end,:,:], B[start +1, :, :] = A[end- 1,:, :] etc. For dims = 2 we do the same but on the second index (i.e. A[:,k,:])

I’m not sure if there is a name for this type of transformation. Another way to think about it is that reverse reverses the indices on the specified dimensions. So it does not explicitly select a midpoint over which the matrix values are flipped. Here is a small example:

Thanks for everyone’s thoughts! That really clears it up a bit more as I was confusing “dimension” with “axis” in the Cartesian sense. I appreciate the logic @Syx_Pek and the example @Christopher_Fisher as well as the terminology @Sukera. Much appreciated for everyone’s support!