-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
numpy.histogram wrong output dtype when using uint8 weights #16616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is likely by design, since chances are you want the output to be the same type as your weights - for example, if you were using I think we have two options here:
Thoughts @seberg, since you've been looking at casting? |
Thanks for your answer. I was looking for a way to do a masked histogram without creating intermediary arrays, for very large images. This I can achieve what I want with a numba function. |
@eric-wieser, I don't think there is anything special about the promotion here. There are two input that may be promoted (or only the weights), and both are There is a point in using reduce-like promotion for |
I try to compute an histogram on a masked image. For this, I pass my mask array (zeros and ones) as weights to
numpy.histogram
. The resulting histogram seems inconsistent.After scratching my head for a while, I noticed that the output dtype of my histogram was
uint8
, and that the problem is most likely an overflow.Reproducing code example:
Error message:
None
Numpy/Python version information:
1.18.2 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)]
The text was updated successfully, but these errors were encountered: