0
0
NumPydata~5 mins

np.unique() for unique elements 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 elements in an array and returns them sorted.

Click to reveal answer
intermediate
How can you get the indices of the unique elements in the original array using np.unique()?

Use the parameter return_index=True. It returns the indices of the first occurrences of the unique values.

Click to reveal answer
intermediate
What does np.unique(array, return_counts=True) return?

It returns two arrays: one with unique elements and one with the count of each unique element in the original array.

Click to reveal answer
beginner
True or False: np.unique() always returns the unique elements in sorted order.

True. The unique elements returned by np.unique() are sorted by default.

Click to reveal answer
beginner
How can np.unique() help in real-life data cleaning?

It helps find all distinct values in data, like unique customer IDs or unique product names, which is useful to remove duplicates or analyze categories.

Click to reveal answer
What does np.unique() return by default?
AOnly the first element
BAll elements including duplicates
CAll unique elements sorted
DRandom elements
Which parameter returns the count of each unique element in np.unique()?
Areturn_counts
Breturn_index
Creturn_inverse
Dreturn_sorted
If you want the indices of unique elements in the original array, which parameter do you use?
Areturn_inverse
Breturn_index
Creturn_positions
Dreturn_counts
Does np.unique() modify the original array?
ANo, it returns the original array unchanged
BYes, it sorts the original array
CYes, it removes duplicates in place
DNo, it returns a new array
What type of data is np.unique() most useful for?
AFinding duplicates in data
BSorting numbers only
CCalculating averages
DCreating random arrays
Explain how you would use np.unique() to find unique values and their counts in a dataset.
Think about the parameters that give you extra information besides unique values.
You got /5 concepts.
    Describe a real-world example where finding unique elements with np.unique() is helpful.
    Consider situations like customer lists or product inventories.
    You got /5 concepts.