Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
26-Nov-2025NumPy 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