#๐Ÿ”’ Array shuffling mapping

27 messages ยท Page 1 of 1 (latest)

small siren
#

I have a question regarding two arrays with 1 a shuffled version of the other. My question is how do we return the shuffled array back to the original array?

zinc cosmosBOT
#

@small siren

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

small siren
#

For Example:

arr1 = np.array([[1, 2, 3],
                 [4, 5, 6],
                 [7, 8, 9]])


arr2 = np.array([[4, 5, 6],
                 [7, 8, 9],
                 [1, 2, 3]])
#

I want to reset arr2 back to arr1 based on the indices on arr1

finite cliff
#
import random

a = [1, 2, 3,4 , 5]
b = somehow_shuffle(a)
a[:] = b
#

you can also shuffle "in place" with random.shuffle

#

ah, those are numpy arrays. My idea might work, or it might not; I don't use numpy

small siren
#

im not talking about how to shuffle, i'm talking about how to return the suffled array back to the original array

static fulcrum
finite cliff
#

might not work, but it shouldn't take long to try it

static fulcrum
small siren
#

im trying to convert arr2 back to arr1

static fulcrum
small siren
#

based on the row indices

static fulcrum
small siren
#

i want to find the index mapping to reshuffle it back

static fulcrum
# small siren based on the row indices

So do you mean that in addition to

arr1 = np.array([[1, 2, 3],
                 [4, 5, 6],
                 [7, 8, 9]])


arr2 = np.array([[4, 5, 6],
                 [7, 8, 9],
                 [1, 2, 3]])
```You also have this
```py
shuffled_indices = [2, 1, 0]
```And you want to use `shuffled_indices` to transform `arr2` back?
small siren
#

yes

#

i think its supposed to be [1, 2, 0]

static fulcrum
#

One problem is that there might be multiple solutions (think duplicate elements)

small siren
#

my problem there wont be duplicates

static fulcrum
zinc cosmosBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.