Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does shuffling an array mean in data science?
Shuffling an array means rearranging its elements in a random order. It helps to mix data so that patterns or order do not bias analysis or models.
Click to reveal answer
beginner
Which NumPy function is used to shuffle arrays in-place?
The function numpy.random.shuffle() shuffles the elements of an array in-place, meaning it changes the original array order randomly.
Click to reveal answer
intermediate
How does numpy.random.shuffle() behave differently for 1D and 2D arrays?
For 1D arrays, it shuffles all elements randomly. For 2D arrays, it shuffles only the rows, keeping the order of elements within each row unchanged.
Click to reveal answer
beginner
Why is shuffling data important before training machine learning models?
Shuffling prevents the model from learning the order of data, which could cause bias. It ensures the model sees a random mix, improving generalization.
Click to reveal answer
intermediate
What is the difference between numpy.random.shuffle() and numpy.random.permutation()?
shuffle() changes the original array in-place. permutation() returns a new shuffled array, leaving the original unchanged.
Click to reveal answer
What does numpy.random.shuffle() do to a 2D array?
AShuffles the rows randomly
BShuffles all elements randomly
CShuffles the columns randomly
DDoes not change the array
✗ Incorrect
For 2D arrays, numpy.random.shuffle() shuffles the rows but keeps the order of elements within each row.
Which function returns a new shuffled array without changing the original?
Anumpy.random.shuffle()
Bnumpy.random.permutation()
Cnumpy.shuffle()
Dnumpy.random.sample()
✗ Incorrect
numpy.random.permutation() returns a new shuffled array and leaves the original array unchanged.
Why should you shuffle data before training a model?
ATo speed up training
BTo increase data accuracy
CTo reduce data size
DTo prevent bias from data order
✗ Incorrect
Shuffling prevents the model from learning patterns based on data order, reducing bias.
What happens when you use numpy.random.shuffle() on a 1D array?
AThe array elements are shuffled randomly
BThe array is sorted
CThe array is reversed
DNothing changes
✗ Incorrect
For 1D arrays, numpy.random.shuffle() rearranges elements in random order.
Is numpy.random.shuffle() a pure function (does it return a new array)?
AYes, it returns a new shuffled array
BYes, it returns a sorted array
CNo, it shuffles the array in-place
DNo, it only returns the indices
✗ Incorrect
numpy.random.shuffle() modifies the original array directly and does not return a new array.
Explain how to shuffle a 1D NumPy array and why shuffling is useful in data science.
Think about randomizing data before training models.
You got /4 concepts.
Describe the difference between numpy.random.shuffle() and numpy.random.permutation() with examples.
One modifies the original, the other creates a new array.
You got /4 concepts.
Practice
(1/5)
1. What does np.random.shuffle() do to a NumPy array?
easy
A. Randomly rearranges the elements of the array in-place
B. Sorts the array elements in ascending order
C. Creates a new shuffled copy of the array without changing the original
D. Reverses the order of elements in the array
Solution
Step 1: Understand the function purpose
np.random.shuffle() is designed to mix elements randomly within the array.
Step 2: Check how it modifies the array
This function changes the original array directly (in-place), not creating a new one.
Final Answer:
Randomly rearranges the elements of the array in-place -> Option A
Quick Check:
Shuffle = random in-place rearrangement [OK]
Hint: Shuffle mixes elements inside the same array [OK]
Common Mistakes:
Thinking shuffle returns a new array
Confusing shuffle with sorting
Assuming shuffle reverses elements
2. Which of the following is the correct syntax to shuffle a 1D NumPy array named arr?
easy
A. np.random.shuffle(arr, axis=1)
B. np.shuffle(arr)
C. arr.shuffle()
D. np.random.shuffle(arr)
Solution
Step 1: Identify the correct function call
The shuffle function is inside the np.random module, so it must be called as np.random.shuffle().
Step 2: Check the parameters
It takes the array as the only argument. The axis parameter is not valid for 1D arrays.