Help me understand imhist, I have to recreate it in Python
Show older comments
I got an array of float point numbers between 0 and 1. imhist is called with 8 bins (it's and old legacy code I have not written myself). So I want to do the same in Python, but when I recreated the function, I found that I don't understand the matlab results. Example:
arr = [0, 0.1, 0.3, 0.6, 0.9];
[res, bins] = imhist(arr, 8);
[bins'; res']
Now writing the same in Python, I get some different results:
arr = np.array([0, 0.1, 0.3, 0.6, 0.9])
bins = np.linspace(0, 1, 8)
w, t = np.histogram(arr, bins)
print(t)
print(w)
The bins are exactly the same, but the result array is
[2 0 1 0 1 0 1]
I get the Python results, there are 2 values between 0 and 0.1429. Furthermore, the result list has 7 elements, as the last bin is the closing number- Matlab has 8 results and like shown, the differ in a way I don't understand.
How do I have to interpret the Matlab results - and more importantly - how do I get the same results in Python?
Accepted Answer
More Answers (0)
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!