Nomenclature of the Reverse Function

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.

Could someone please continue to explain this to me? Thanks!

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,:])

3 Likes

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:

x = [1 2 3; 4 5 6; 7 8 9]

julia> reverse(x, dims=1)
3×3 Array{Int64,2}:
 7  8  9
 4  5  6
 1  2  3

 x[[3,2,1],:]

julia>  x[[3,2,1],:]
3×3 Array{Int64,2}:
 7  8  9
 4  5  6
 1  2  3

As you can see, I produced the same result by indexing the rows in descending order.

1 Like

I’d call it “reversing along dimension x”

2 Likes

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!