The Wayback Machine - https://web.archive.org/web/20240119133037/https://www.geeksforgeeks.org/numpy-random-shuffle-in-python/
Open In App
Related Articles

numpy.random.shuffle() in python

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

With the help of numpy.random.shuffle() method, we can get the random positioning of different integer values in the numpy array or we can say that all the values in an array will be shuffled randomly.

Syntax : numpy.random.shuffle(x)

Return : Return the reshuffled numpy array.

Example #1 :

In this example we can see that by using numpy.random.shuffle() method, we are able to do the reshuffling of values in the numpy array or change the positions of values in an array.

Python3




# import numpy
import numpy as np
import matplotlib.pyplot as plt
  
gfg = np.arange(10)
# Using shuffle() method
np.random.shuffle(gfg)
  
print(gfg)


Output :

[7 1 5 0 8 4 3 9 6 2]

Example #2 :

Python3




# import numpy
import numpy as np
import matplotlib.pyplot as plt
  
gfg = np.arange(16).reshape((4, 4))
# Using shuffle() method
np.random.shuffle(gfg)
  
print(gfg)


Output :

[[ 4  5  6  7]

[ 0  1  2  3]

[ 8  9 10 11]

[12 13 14 15]]

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 18 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials