Random Permutations using Numpy.
Ask by ICSM Computer
Updated 26 Nov 2025
NumPy provides two important functions for this:
1.
numpy.random.permutation()Creates a new shuffled copy of a sequence or array.
Example 1: Shuffle numbers 0 to 9
Output example:
Example 2: Shuffle an existing array
Output:
2.
numpy.random.shuffle()Shuffles the original array in-place (modifies the existing one).
Example:
Output (original array is changed):
Difference Between permutation() and shuffle()
np.random.permutation()np.random.shuffle()Permuting Multi-Dimensional Arrays
permutation() always shuffles rows:
Possible output:
Randomly Shuffle List (Python list)
NumPy also works with Python lists:
Summary
np.random.permutation()when you want a new shuffled copynp.random.shuffle()when you want to shuffle in-place