# Nomenclature of the Reverse Function

**URL:** <https://discourse.julialang.org/t/nomenclature-of-the-reverse-function/50887>\
**Category:** New to Julia\
**Tags:** question, first-steps, array, syntax\
**Created:** [November 28, 2020, 4:48am UTC](https://discourse.julialang.org/t/nomenclature-of-the-reverse-function/50887 "2020-11-28T04:48:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [November 28, 2020, 4:48am UTC](https://discourse.julialang.org/t/nomenclature-of-the-reverse-function/50887/1 "2020-11-28T04:48:13Z")

</div>

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.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/1/d118cd03a793eae2c6ecec65f02cc4e9c4976790.png)

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

---

<div class="post-metadata">

**Author:** ![Syx\_Pek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/syx_pek/32/6364_2.png) [@Syx\_Pek](https://discourse.julialang.org/u/Syx_Pek)\
**Post date:** [November 28, 2020, 8:55am UTC](https://discourse.julialang.org/t/nomenclature-of-the-reverse-function/50887/2 "2020-11-28T08:55:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 28, 2020, 9:01am UTC](https://discourse.julialang.org/t/nomenclature-of-the-reverse-function/50887/3 "2020-11-28T09:01:39Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 28, 2020, 10:09pm UTC](https://discourse.julialang.org/t/nomenclature-of-the-reverse-function/50887/4 "2020-11-28T22:09:53Z")

</div>

I’d call it “reversing along dimension x”

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [November 28, 2020, 10:16pm UTC](https://discourse.julialang.org/t/nomenclature-of-the-reverse-function/50887/5 "2020-11-28T22:16:24Z")

</div>

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!
