Wednesday, December 25, 2024
Google search engine
HomeLanguagesnumpy.random.shuffle() in python

numpy.random.shuffle() in python

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

RELATED ARTICLES

Most Popular

Recent Comments