# Finding the new order of shuffled array

**URL:** <https://discourse.julialang.org/t/finding-the-new-order-of-shuffled-array/78611>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 28, 2022, 1:02pm UTC](https://discourse.julialang.org/t/finding-the-new-order-of-shuffled-array/78611 "2022-03-28T13:02:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kali](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kali](https://discourse.julialang.org/u/Kali)\
**Post date:** [March 28, 2022, 1:02pm UTC](https://discourse.julialang.org/t/finding-the-new-order-of-shuffled-array/78611/1 "2022-03-28T13:02:14Z")

</div>

Hello Julia users! I was having a problem while writing some code that I hope you can help with. So basically what I want to do is that I have an original array A of some length which contains some integers. This array has a corresponding order of the elements. If I then shuffle A I am interested in extracting the new order of the elements in a nice way. Perhaps the code makes it more clear:

```julia
A = [11,13,25,10,9]
#The corresponding order of this original A-vector would be:
Order = [1,2,3,4,5]
#If we then Shuffle our A-vector we should get a new vector:
A_Shuffled = shuffle(A)
#This eg. gives
A_Shuffled = [25,13,10,9,11]
#What I am interested in extracting is then the new order which should be:
Order_Shuffled = [3,2,4,5,1]

```

This is of course doable by using a for-loop and then finding the new indices of the elements in the original A-vector using findall, but I was wondering if there was a more clean approach to doing it. I couldn’t find anything by searching for it, so I hope you guys can help 🙂

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [March 28, 2022, 1:14pm UTC](https://discourse.julialang.org/t/finding-the-new-order-of-shuffled-array/78611/2 "2022-03-28T13:14:11Z")

</div>

You can shuffle the indexes instead of the original array:

```julia
A = [11,13,25,10,9]
p = shuffle(eachindex(A)) # new order of elements
A_shuffled = A[p]

```

If you really want to find the index only after shuffling the original array, you can use `indexin(A_shuffled, A)`.

---

<div class="post-metadata">

**Author:** ![Kali](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kali](https://discourse.julialang.org/u/Kali)\
**Post date:** [March 28, 2022, 1:19pm UTC](https://discourse.julialang.org/t/finding-the-new-order-of-shuffled-array/78611/3 "2022-03-28T13:19:46Z")

</div>

Thank you 🙂 Solved my problem!
