0
0
NumPydata~15 mins

Histogram computation with np.histogram() in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Histogram computation with np.histogram()
📖 Scenario: You work in a small bakery that tracks the number of cookies sold each day. You want to understand how cookie sales are spread over a week to plan better.
🎯 Goal: Build a program that uses np.histogram() to find how many days fall into different sales ranges.
📋 What You'll Learn
Create a numpy array with daily cookie sales
Set up bins to group sales counts
Use np.histogram() to compute the histogram
Print the histogram counts
💡 Why This Matters
🌍 Real World
Histograms help businesses understand how data like sales or customer visits are spread across ranges.
💼 Career
Data scientists and analysts use histograms to summarize and visualize data distributions quickly.
Progress0 / 4 steps
1
Create the daily sales data
Create a numpy array called daily_sales with these exact values: 12, 15, 7, 10, 20, 25, 18.
NumPy
Need a hint?

Use np.array() to create the array with the given numbers.

2
Set up bins for sales ranges
Create a list called bins with these exact values: 0, 10, 20, 30. These will group sales into ranges 0-10, 10-20, and 20-30.
NumPy
Need a hint?

Bins are the edges that separate groups. Use a list with the given numbers.

3
Compute the histogram
Use np.histogram() with daily_sales and bins to compute the histogram. Save the counts in a variable called hist_counts and the bin edges in hist_bins.
NumPy
Need a hint?

Call np.histogram() with the array and bins, and unpack the result into two variables.

4
Print the histogram counts
Print the variable hist_counts to show how many days fall into each sales range.
NumPy
Need a hint?

Use print(hist_counts) to display the counts.