0
0
NumPydata~15 mins

Why array creation matters in NumPy - See It in Action

Choose your learning style9 modes available
Why array creation matters
📖 Scenario: Imagine you are a data analyst working with sales data. You want to organize daily sales numbers into a structure that makes it easy to analyze and calculate totals.
🎯 Goal: You will create a NumPy array to hold sales data, set a threshold for high sales, filter the data based on this threshold, and finally display the filtered sales numbers.
📋 What You'll Learn
Create a NumPy array called sales with these exact values: 10, 25, 30, 5, 40
Create a variable called threshold and set it to 20
Use a NumPy expression to create a new array called high_sales that contains only sales values greater than threshold
Print the high_sales array
💡 Why This Matters
🌍 Real World
Data scientists often need to organize and filter data efficiently to find important information quickly.
💼 Career
Knowing how to create and filter arrays is a basic skill for data analysis and machine learning tasks.
Progress0 / 4 steps
1
Create the sales data array
Import NumPy as np and create a NumPy array called sales with these exact values: 10, 25, 30, 5, 40
NumPy
Need a hint?

Use np.array([...]) to create the array.

2
Set the sales threshold
Create a variable called threshold and set it to the number 20
NumPy
Need a hint?

Just assign the number 20 to threshold.

3
Filter sales above the threshold
Use a NumPy expression to create a new array called high_sales that contains only the values in sales greater than threshold
NumPy
Need a hint?

Use boolean indexing: sales[sales > threshold].

4
Display the filtered sales
Print the high_sales array to show the sales numbers greater than the threshold
NumPy
Need a hint?

Use print(high_sales) to display the array.