Write a NumPy program to compute the histogram of nums against the bins.
import numpy as np import matplotlib.pyplot as plt nums = np.array([0.5, 0.7, 1.0, 1.2, 1.3, 2.1]) bins = np.array([0, 1, 2, 3]) print("nums: ",nums) print("bins: ",bins) print("Result:", np.histogram(nums, bins)) plt.hist(nums, bins=bins) plt.show()
Sample Output:
nums: [0.5 0.7 1. 1.2 1.3 2.1] bins: [0 1 2 3] Result: (array([2, 3, 1], dtype=int64), array([0, 1, 2, 3]))
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer