0
0
NumPydata~10 mins

Shuffling arrays in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Shuffling Arrays with NumPy
📖 Scenario: You are working with a list of student IDs for a class. You want to randomly shuffle the order of these IDs to assign presentation slots fairly.
🎯 Goal: Learn how to shuffle a NumPy array to randomize the order of elements.
📋 What You'll Learn
Create a NumPy array with specific student IDs
Set a random seed for reproducibility
Shuffle the array using NumPy
Print the shuffled array
💡 Why This Matters
🌍 Real World
Randomly shuffling data is useful in experiments, games, and fair assignments like presentations or seating.
💼 Career
Data scientists often shuffle data to prepare for training machine learning models or to randomize samples.
Progress0 / 4 steps
1
Create the NumPy array
Import NumPy as np and create a NumPy array called student_ids with these exact values: 101, 102, 103, 104, 105.
NumPy
Need a hint?

Use np.array() to create the array with the given numbers.

2
Set the random seed
Set the random seed to 42 using np.random.seed(42) to make the shuffle results reproducible.
NumPy
Need a hint?

Use np.random.seed(42) before shuffling to get the same random order every time.

3
Shuffle the array
Use np.random.shuffle(student_ids) to shuffle the student_ids array in place.
NumPy
Need a hint?

Call np.random.shuffle() with the array you want to shuffle.

4
Print the shuffled array
Print the student_ids array to see the shuffled order.
NumPy
Need a hint?

Use print(student_ids) to display the shuffled array.