VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-randomly-select-rows-of-an-array-in-python-with-numpy/

⇱ How to randomly select rows of an array in Python with NumPy ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to randomly select rows of an array in Python with NumPy ?

Last Updated : 23 Jul, 2025

 In this article, we will see two different methods on how to randomly select rows of an array in Python with NumPy. Let's see different methods by which we can select random rows of an array:

Method 1: We will be using the function shuffle(). The shuffle() function shuffles the rows of an array randomly and then we will display a random row of the 2D array.

Output:

👁 Image

Method 2: First create an array, then apply the sample() method to it and display a single row.

Output:

👁 Image

Method 3: We will be using the function choice(). The choices() method returns multiple random elements from the list with replacement. 

Now lets, select rows from the list of random integers that we have created.

Output:

👁 Image
Comment