Density heights and bin areas
Predict the output · Medium · §8.3 Comparing groups by density
The code splits the hours that 8 students spent playing games in a day into bins 2 hours wide and computes the density. Predict the three lines of output without running the code.
Code
import numpy as np
hours = [3, 1, 2, 6, 3, 2, 4, 3]
edges = [0, 2, 4, 6, 8]
density, _ = np.histogram(hours, bins=edges, density=True)
print(density.tolist())
print(float(density[1] * 2))
print(float((density * 2).sum()))Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.