-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
numpy.histogram(a, bins) behaves differently from numpy.histogram(a, bins, range=(a.min(), a.max())) #11780
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
Can you show the values of I suspect this is fixed in 1.15.0 - so alternatively, can you try reproducing on the latest version? |
It's 32K lines, so I hope the attached zipped pickle helps. In order to replicate, once you unzip the file, here's the code: import pickle
bins=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0, 210.0, 220.0, 230.0, 240.0, 250.0, 260.0, 270.0, 280.0, 290.0, 300.0, 310.0, 320.0, 330.0, 340.0, 350.0, 360.0]
outFile = open('output.pickle','rb')
a = pickle.load(outFile)
np.histogram(a, bins=bins, range=(b.min(), b.max())) # THIS WORKS
#np.histogram(a, bins=bins) # THIS WILL RETURN ERROR 'ValueError: range parameter must be finite.' |
What is |
Sorry, it was a.min(), a.max(), i.e.: import pickle
bins=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0,
8000
90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0, 210.0, 220.0, 230.0, 240.0, 250.0, 260.0, 270.0, 280.0, 290.0, 300.0, 310.0, 320.0, 330.0, 340.0, 350.0, 360.0]
outFile = open('output.pickle','rb')
a = pickle.load(outFile)
np.histogram(a, bins=bins, range=(a.min(), a.max())) # THIS WORKS
#np.histogram(a, bins=bins) # THIS WILL RETURN ERROR 'ValueError: range parameter must be finite.' Great, then, will update to 1.15.0! Out of curiosity, what is it that triggers the exception? I'm curious as the documented behaviour is that not providing an explicit range value for |
Note that you may encounter #11628 "RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88" which will be fixed in 1.15.1. I think the problem was the NAN in |
Ah, thanks for flagging that up! On the NAN in a: if that is the problem, how come specifying the range explicitly does work? Shouldn't it fail too? (At least if the docs are correct?) |
There was a bug, perhaps #7503 is relevant. |
Thanks @mattip - I'll report back to gboeing/osmnx#196. |
As reported in gboeing/osmnx#196, while running OSMnx's code, which directly references numpy.histogram().
It's tricky to reproduce without fully using the jupyter notebook in the example, but I'll do my best to summarise and I'm happy to test things and report back if required. I'm sorry if this issue is filed in a substandard way.
Reproducing code example:
While running the jupyter notebook above, which aims to calculate a histogram over a set of bearings extracted from Open Street Map, I have the following behaviour.
This works:
np.histogram(bearings, bins=bins, range=(bearings.min(), bearings.max()))
but this doesn't
np.histogram(bearings, bins=bins)
.My understanding from the documentation is that the two calls should work exactly the same, so I'm puzzled.
Error message:
Numpy/Python version information:
!pip list returns
numpy 1.14.5
conda list returns
numpy 1.14.5
numpy 1.13.1 py36_0
'import sys, numpy; print(numpy.version, sys.version)' returns
1.14.5 3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 13:44:09)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
The text was updated successfully, but these errors were encountered: