0
0
NumPydata~15 mins

np.prod() for product in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Calculate Product of Numbers Using np.prod()
📖 Scenario: Imagine you are working in a small business that sells boxes of chocolates. You want to find the total number of chocolates if you multiply the number of chocolates in each box.
🎯 Goal: You will create a list of numbers representing chocolates in each box, then use np.prod() to find the total product of chocolates.
📋 What You'll Learn
Create a numpy array with exact values
Create a variable to hold the product using np.prod()
Print the product value
💡 Why This Matters
🌍 Real World
Calculating total quantities or combined values by multiplying numbers is common in inventory management, finance, and science.
💼 Career
Data scientists often use numpy functions like <code>np.prod()</code> to quickly compute products of data arrays for analysis and modeling.
Progress0 / 4 steps
1
Create a numpy array of chocolates
Import numpy as np and create a numpy array called chocolates with these exact values: 2, 3, 4.
NumPy
Need a hint?

Use np.array() to create the array with the numbers 2, 3, and 4.

2
Calculate the product of chocolates
Create a variable called total_chocolates and set it to the product of all elements in chocolates using np.prod().
NumPy
Need a hint?

Use np.prod(chocolates) to multiply all numbers in the array.

3
Print the total product
Write a print() statement to display the value of total_chocolates.
NumPy
Need a hint?

Use print(total_chocolates) to show the product result.

4
Calculate product for a new array
Create a new numpy array called boxes with values 5, 6, 7. Then calculate the product using np.prod() and store it in total_boxes. Finally, print total_boxes.
NumPy
Need a hint?

Create boxes = np.array([5, 6, 7]), then total_boxes = np.prod(boxes), and print it.