`numpy.histogram` is returning an array of `int64`, which is breaking compatibility with bindings/C wrapper code
See original GitHub issueDue to this change:
# Histogram is an integer or a float array depending on the weights.
if weights is None:
ntype = np.dtype(np.intp) # <---
else:
ntype = weights.dtype
numpy.histogram
is choosing intp
as the return type for the histogram values. This is breaking compatibility with wrapper code that expects simple int
s (int32
are fine, as are python long
, but usually C wrapper code can’t handle numpy.int64
). What is worse is that the behaviour is platform-dependent (i.e., it keeps working on 32-bit platforms).
Could it be changed to simply use int
as dtype
(i.e., would use numpy.int32
)?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
numpy.histogram — NumPy v1.24 Manual
If bins is a sequence, it defines a monotonically increasing array of bin edges, including the rightmost edge, allowing for non-uniform bin widths....
Read more >How to make a numpy histogram contain the right bin edge ...
By default the bins in numpy.histogram work by including the left bin edge and not the right bin edge. For example: array =...
Read more >NumPy.histogram() Method in Python - GeeksforGeeks
A histogram is the best way to visualize the frequency distribution of a dataset by splitting it into small equal-sized intervals called ...
Read more >Python Histogram Plotting: NumPy, Matplotlib, Pandas ...
Large array of data, and you want to compute the “mathematical” histogram that represents bins and the corresponding frequencies. NumPy's np. histogram() and ......
Read more >NumPy compatibility — boost-histogram docs
Accessing the storage array#. You can access the storage of any Histogram using .view() , see Histogram. NumPy tuple ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You generally want to use
PyNumber
API instead of thePyLong
API if you want to be able to use numpy scalar objects. You don’t need to use the numpy API.In a 64 bit system you could have an input to histogram having more than
2**31 - 1
identical values, which would result in anint32
overflowing. So I think it is pretty much uncontroversial that the right thing to do is to go withnp.intp
.It’s hard to tell without knowing more details, but the issue here seems to be that your wrapper code is not ready to work on 64 bit systems, and you will need to adapt it to fix that, not expect NumPy to sacrifice correctness for your convenience.