0
0
NumPydata~5 mins

np.unique() for unique values in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AOriginal array with duplicates removed but order kept
BIndices of duplicates
CSorted unique values from the array
DSum of unique values
How do you get the count of each unique value using np.unique()?
ASet <code>return_counts=True</code>
BSet <code>return_index=True</code>
CUse <code>np.count()</code>
DUse <code>np.sum()</code>
Which argument helps find unique rows in a 2D array?
A<code>sorted=False</code>
B<code>axis=1</code>
C<code>return_index=True</code>
D<code>axis=0</code>
What type of object does np.unique() return?
AA Python list of unique values
BA sorted NumPy array of unique values
CA dictionary with counts
DA scalar value
If you want the indices of unique values in the original array, which parameter do you use?
A<code>return_index=True</code>
B<code>return_inverse=True</code>
C<code>return_counts=True</code>
D<code>axis=1</code>
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.