0
0
NumPydata~15 mins

np.unique() for unique values in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Finding Unique Values with np.unique()
📖 Scenario: You work in a store that tracks daily sales of different fruits. Sometimes the same fruit is sold multiple times in a day. You want to find out which unique fruits were sold today.
🎯 Goal: Build a small program that uses np.unique() to find all unique fruits sold from a list of sales.
📋 What You'll Learn
Create a numpy array called sales with the exact fruit names given.
Create a variable called unique_fruits that stores the unique fruit names using np.unique().
Print the unique_fruits array to see the result.
💡 Why This Matters
🌍 Real World
Stores and businesses often need to find unique items sold or listed to analyze inventory or sales trends.
💼 Career
Data analysts and scientists use <code>np.unique()</code> to quickly find unique values in datasets for reporting and decision making.
Progress0 / 4 steps
1
Create the sales data array
Create a numpy array called sales with these exact fruit names in this order: 'apple', 'banana', 'apple', 'orange', 'banana', 'kiwi'.
NumPy
Need a hint?

Use np.array([...]) to create the array with the exact fruit names.

2
Set up the variable for unique fruits
Create a variable called unique_fruits and set it to None for now as a placeholder.
NumPy
Need a hint?

This step just prepares the variable. We will update it next.

3
Find unique fruits using np.unique()
Use np.unique() on the sales array and assign the result to the variable unique_fruits.
NumPy
Need a hint?

Call np.unique() with sales inside the parentheses.

4
Print the unique fruits
Print the variable unique_fruits to display the unique fruit names.
NumPy
Need a hint?

Use print(unique_fruits) to show the unique fruits.