0
0
NumPydata~15 mins

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

Choose your learning style9 modes available
Find Unique Elements Using np.unique()
📖 Scenario: You work in a store and have a list of product IDs sold today. Some products were sold multiple times.You want to find out which unique products were sold to understand your sales better.
🎯 Goal: Build a small program that uses np.unique() to find unique product IDs from a list.
📋 What You'll Learn
Create a numpy array called product_ids with the exact values: [101, 203, 101, 405, 203, 507]
Create a variable called unique_products to store unique product IDs using np.unique()
Print the unique_products array to see the unique product IDs
💡 Why This Matters
🌍 Real World
Finding unique items in sales data helps stores understand what products are popular and manage inventory better.
💼 Career
Data scientists often need to clean and analyze data by identifying unique values to prepare datasets for further analysis.
Progress0 / 4 steps
1
Create the product IDs array
Create a numpy array called product_ids with these exact values: [101, 203, 101, 405, 203, 507]
NumPy
Need a hint?

Use np.array() to create the array with the exact list of numbers.

2
Use np.unique() to find unique product IDs
Create a variable called unique_products and assign it the result of np.unique(product_ids) to find unique product IDs.
NumPy
Need a hint?

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

3
Print the unique product IDs
Write a print statement to display the unique_products array.
NumPy
Need a hint?

Use print(unique_products) to show the unique product IDs.

4
Complete program to find and print unique product IDs
Combine all previous steps to create a complete program that imports numpy, creates the product_ids array, finds unique products with np.unique(), and prints the result.
NumPy
Need a hint?

Run the full program to see the unique product IDs printed.