Recall & Review
beginner
What does the function
np.unique() do in NumPy?np.unique() finds all the unique values in a NumPy array and returns them sorted.
Click to reveal answer
intermediate
How can you get the indices of the unique values in the original array using
np.unique()?Use the argument return_index=True. It returns the indices of the first occurrences of the unique values.
Click to reveal answer
intermediate
What does the
return_counts=True option do in np.unique()?It returns how many times each unique value appears in the original array.
Click to reveal answer
intermediate
If you want to find unique rows in a 2D NumPy array, can
np.unique() help?Yes, by using axis=0, np.unique() returns unique rows.
Click to reveal answer
beginner
What is the order of the unique values returned by
np.unique()?The unique values are always returned sorted in ascending order.
Click to reveal answer
What does
np.unique() return by default?✗ Incorrect
By default, np.unique() returns the sorted unique values from the input array.
How do you get the count of each unique value using
np.unique()?✗ Incorrect
The return_counts=True option returns the count of each unique value.
Which argument helps find unique rows in a 2D array?
✗ Incorrect
Using axis=0 tells np.unique() to find unique rows.
What type of object does
np.unique() return?✗ Incorrect
np.unique() returns a sorted NumPy array of unique values.
If you want the indices of unique values in the original array, which parameter do you use?
✗ Incorrect
return_index=True returns the indices of the first occurrences of unique values.
Explain how to use
np.unique() to find unique values and their counts in a NumPy array.Think about the arguments that give extra information besides unique values.
You got /5 concepts.
Describe how to find unique rows in a 2D NumPy array using
np.unique().Consider the axis argument for row-wise uniqueness.
You got /4 concepts.