Skip to content
Related Articles
numpy.random.shuffle() in python
• Last Updated : 18 Aug, 2020

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

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up