shuffle two arrays the same way python

# Example usage using random:
import random
# Say you want to shuffle (randomly reorder) the following lists in the
# same way (e.g. because there's an association between the elements that
# you want to maintain):
your_list_1 = ['the', 'original', 'order']
your_list_2 = [1, 2, 3]

# Steps to shuffle:
joined_lists = list(zip(your_list_1, your_list_2))
random.shuffle(joined_lists) # Shuffle "joined_lists" in place
your_list_1, your_list_2 = zip(*joined_lists) # Undo joining
print(your_list_1)
print(your_list_2)
--> ('the', 'order', 'original') # Both lists shuffled in the same way
--> (1, 3, 2) # Use list(your_list_2) to convert to list

4.22
8
Zikato 95 points

                                    def unison_shuffled_copies(a, b):
    assert len(a) == len(b)
    p = numpy.random.permutation(len(a))
    return a[p], b[p]

4.22 (9 Votes)
0
5
1

                                    >>> import numpy as np
>>> x = np.arange(10)
>>> y = np.arange(9, -1, -1)
>>> x
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> y
array([9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
>>> s = np.arange(x.shape[0])
>>> np.random.shuffle(s)
>>> s
array([9, 3, 5, 2, 6, 0, 8, 1, 4, 7])
>>> x[s]
array([9, 3, 5, 2, 6, 0, 8, 1, 4, 7])
>>> y[s]
array([0, 6, 4, 7, 3, 9, 1, 8, 5, 2])

5 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to shuffle two arrays python shuffle numpy arrays in same order same random shuffling in two numpy arrays how to shuffle two arrays simultaneously in python random shuffle two lists numpy shuffle 2 arrays together shuffle 2 arrays in the same way how to shuffle two lists in python how to shuffle 2 arrays the same way shuffle two numpy arrays in order how to shuffle two numpy arrays together how to shuffle two different arrays with the same length the same way shuffle multiple lists python how to shuffle two arrays the same way python numpy shuffle two arrays with same how to shuffle 2 arrays in the same way with pytjon shuffle 2 lists numpy shuffle two arrays in the same way shuffle 2 lists the same numpy shuffle 2 arrays the same way how to shuffle np array two array in same way how to shuffle np array two array randomly merging two numpy arrays randomly merge 4 numpy arrays into 2 arrays shuffle two lists the same way python python shuffle 2 arrays in the same way shuffle two arrays together python shuffle two lists in the same order shuffle two arrays numpy python shuffle two lists together numpy randomly reorder two arrays python shuffle two lists the same way shuffle two list in the same way python shuffle two arrays in the same way python shuffle 2 lists python in the same way shuffle python avec 2 lists the same way np shuffle two arrays the same way how to shuffle two lists having same order shuffle two lists together to one randomly shuffle 2 lists the same way .reindex() shuffle two np arrays together python shuffle 2 lists together shuffle 2 lists python shuffle two lists in the same order python multiplying two arrays in python multiplying two arrays python how numpy array insert others numpy arrays with different dimensions how to exchange random element from two np array in python randomize elements between two numpy arrays python how to randomly interchange elements of two numpy array shuffle two lists together python how to shuffle two numpy arrays with same order shuffle two numpy arrays how to shuffle two lists the same way python shuffle 2 arrays in the same order np shuffle 2 arrayq python shuffer np array the same way shuffle two vectors the same numpy python random shuffle two lists shuffle two lists at the same time python 3 randomize two numpy arrays together shuffle two arrays in same order in python numpy shuffle between two indexes python randomize 2 lists equally one line python randomize 2 lists equally how to shuffle two np arrays python np.random.shuffle with two matrix np.random.shuffle with two arrays python shuffle-two-lists-at-once-with-same-order numpy shuffle zip combine and shuffle two lists in python numpy shuffle two arrays in same way python shuffle two lists in the same way np shuffle two arrays python shuffle two arrays the same way how to shuffle and x and y in numpy array toghther shuffle two np.array with same random_state shuffle two array together python shuffle two numpy arrays in same order shuffle two arrays in the same way shuffle two arrays in same order python how to shuffle 2 arrays so the index is the same python how to shuffle 2 arrays so the index is the same how to shuffle multiple arrays in same order hot to shuffle multiple arrays in same order numpy random shuffle multiple arrays python shuffle numpy arrays and list the same way shuffle two numpy array equally shuffle in numpy shuffle 2 arrays simiultaneously concatenate and shuffle two numpy arrays shuffled array as a index for another array numpy shuffled array as a index for ampther array random shuffle two arrays shuffle two numpy arrays together shuffle two arrays the same way python shuffle two matrix with same order in python how to shuffle 2 numpy arrays how to shuffle two arrays simultaneously how to shuffle two arrays the same way pytorch numpy arrays shuffle simultaneously numpy shuffle two arrays together python shuffle array with 2 numpy shuffle arrays together numpy shuffle two arrays shuffle two arrays the same way numpy shuffle rows of two arrays simultaneously shuffle 2 numpy arrays together shuffle 2 arrays python shuffle numpy two arrays shuffle two np arrays together how to shuffle two arrays whilst keeping indicies same python numpy shuffle two arrays the same way
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source