The Wayback Machine - https://web.archive.org/web/20230512160717/https://www.geeksforgeeks.org/numpy-random-shuffle-in-python/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

numpy.random.shuffle() in python

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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]]

My Personal Notes arrow_drop_up
Last Updated : 18 Aug, 2020
Like Article
Save Article
Similar Reads
Related Tutorials