0
0
NumPydata~10 mins

np.setdiff1d() for difference in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Find Unique Items Using np.setdiff1d()
📖 Scenario: Imagine you have two lists of products from two different stores. You want to find which products are available in the first store but not in the second store.
🎯 Goal: Build a small program that uses np.setdiff1d() to find items unique to the first list.
📋 What You'll Learn
Create two numpy arrays with exact product names
Create a variable to hold the difference using np.setdiff1d()
Print the resulting array of unique items
💡 Why This Matters
🌍 Real World
Finding unique items between two lists is common in inventory management, customer lists, or comparing datasets.
💼 Career
Data analysts and scientists often need to compare datasets to find differences or unique entries.
Progress0 / 4 steps
1
Create the product lists
Create a numpy array called store1_products with these exact items: 'apple', 'banana', 'cherry', 'date', 'fig'.
NumPy
Need a hint?

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

2
Create the second product list
Create a numpy array called store2_products with these exact items: 'banana', 'date', 'elderberry', 'grape'.
NumPy
Need a hint?

Use np.array([...]) again to create the second list with the exact product names.

3
Find products unique to the first store
Create a variable called unique_to_store1 that uses np.setdiff1d() to find items in store1_products that are not in store2_products.
NumPy
Need a hint?

Use np.setdiff1d(array1, array2) to find items in array1 not in array2.

4
Print the unique products
Print the variable unique_to_store1 to display the products unique to the first store.
NumPy
Need a hint?

Use print(unique_to_store1) to show the result.