Q:

Write a NumPy program to compute the histogram of nums against the bins

0

Write a NumPy program to compute the histogram of nums against the bins.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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]))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now