Challenge - 5 Problems
Bin Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of bin counts using numpy histogram
What is the output of the following code that calculates bin counts for the given data array?
Matplotlib
import numpy as np data = np.array([1, 2, 2, 3, 4, 5, 5, 5, 6]) bin_counts, bin_edges = np.histogram(data, bins=3) print(bin_counts)
Attempts:
2 left
💡 Hint
Remember that numpy.histogram divides the data range into equal-width bins and counts how many values fall into each bin.
✗ Incorrect
The data ranges from 1 to 6. Dividing into 3 bins gives edges roughly at [1, 2.666..., 4.333..., 6]. The counts are: 1,2,2 fall into first bin (3 items), 3,4 fall into second bin (2 items), and 5,5,5,6 fall into third bin (4 items).
❓ data_output
intermediate2:00remaining
Bin edges from numpy histogram
What are the bin edges returned by numpy.histogram for the data below with 4 bins?
Matplotlib
import numpy as np data = np.array([10, 15, 20, 25, 30, 35, 40]) bin_counts, bin_edges = np.histogram(data, bins=4) print(bin_edges)
Attempts:
2 left
💡 Hint
Bin edges split the range from min to max into equal parts.
✗ Incorrect
The data ranges from 10 to 40. Dividing into 4 bins means edges at 10, 17.5, 25, 32.5, and 40.
❓ visualization
advanced3:00remaining
Histogram bin count visualization
Which histogram plot corresponds to the bin counts produced by the code below?
Matplotlib
import matplotlib.pyplot as plt import numpy as np data = np.array([2, 4, 4, 4, 5, 5, 7, 9]) plt.hist(data, bins=3) plt.show()
Attempts:
2 left
💡 Hint
Check how matplotlib divides the range into bins and counts data points in each bin.
✗ Incorrect
The data ranges from 2 to 9. Dividing into 3 bins gives edges roughly at [2, 4.333..., 6.666..., 9]. The counts are: 2,4,4,4 fall into first bin (4 items), 5,5 fall into second bin (2 items), 7,9 fall into third bin (2 items).
🧠 Conceptual
advanced1:30remaining
Effect of bin number on histogram shape
How does increasing the number of bins in a histogram affect the bin counts and bin edges?
Attempts:
2 left
💡 Hint
Think about splitting the data range into more parts.
✗ Incorrect
Increasing bins divides the data range into more, smaller intervals. Each bin covers a smaller range, so fewer data points fall into each bin, and the number of bin edges increases.
🔧 Debug
expert2:00remaining
Identify the error in bin edge calculation
What error will the following code produce and why?
Matplotlib
import numpy as np data = np.array([1, 2, 3, 4, 5]) bin_counts, bin_edges = np.histogram(data, bins=[1, 2, 3]) print(bin_edges)
Attempts:
2 left
💡 Hint
Check if the bins argument is valid as a sequence of edges.
✗ Incorrect
The bins argument is a valid sequence of bin edges. The data points 1,2,3 fall into bins [1,2) and [2,3). No error occurs and bin_edges output is [1, 2, 3].