Using np.choose() for Conditional Selection
📖 Scenario: Imagine you are analyzing sales data for a small store. You want to categorize daily sales numbers into different labels based on their values.
🎯 Goal: You will create a NumPy array of sales numbers, define conditions to categorize these sales, use np.choose() to assign category labels, and finally display the categorized results.
📋 What You'll Learn
Create a NumPy array called
sales with exact values: [150, 85, 230, 45, 120]Create a NumPy array called
conditions with three conditions for sales: less than 50, between 50 and 150 (inclusive), and greater than 150Use
np.choose() with the conditions array to assign categories: 'Low', 'Medium', and 'High'Print the final array of category labels
💡 Why This Matters
🌍 Real World
Categorizing data based on conditions is common in sales analysis, customer segmentation, and many other fields.
💼 Career
Data scientists often use conditional selection to prepare data for analysis and reporting.
Progress0 / 4 steps