0
0
NumPydata~30 mins

Why linear algebra matters in NumPy - See It in Action

Choose your learning style9 modes available
Why linear algebra matters
📖 Scenario: Imagine you work at a small store that sells three types of fruits: apples, bananas, and oranges. You want to understand how many fruits you sold in total each day and how much money you made. Linear algebra helps you organize and calculate this information quickly using arrays.
🎯 Goal: You will create arrays to represent daily fruit sales and prices, then use linear algebra (matrix multiplication) to find total sales and total revenue.
📋 What You'll Learn
Use numpy arrays to store data
Use matrix multiplication to calculate totals
Print the total fruits sold each day and total revenue
💡 Why This Matters
🌍 Real World
Stores and businesses use linear algebra to quickly calculate sales totals and revenue from multiple products over time.
💼 Career
Data analysts and scientists use these techniques to summarize and analyze sales data efficiently.
Progress0 / 4 steps
1
Create the sales data array
Create a numpy array called sales with these exact values representing fruits sold over 3 days: Day 1: 10 apples, 5 bananas, 8 oranges; Day 2: 7 apples, 3 bananas, 6 oranges; Day 3: 12 apples, 8 bananas, 5 oranges.
NumPy
Need a hint?

Use np.array and enter the data as a list of lists, each inner list for one day.

2
Create the price array
Create a numpy array called prices with these exact values representing the price per fruit: 2 for apples, 1 for bananas, and 1.5 for oranges.
NumPy
Need a hint?

Use np.array with a single list for prices.

3
Calculate total fruits sold each day
Create a numpy array called total_fruits by summing the sales array across the fruit columns (axis 1).
NumPy
Need a hint?

Use the sum method with axis=1 to add across columns (fruits).

4
Calculate total revenue and print results
Create a numpy array called total_revenue by multiplying sales with prices using matrix multiplication. Then print total_fruits and total_revenue.
NumPy
Need a hint?

Use the @ operator for matrix multiplication. Then use print to show results.