0

Possibly a duplicate of Pandas/Python: 2D histogram fails with value error. But the solution proposed there is not working for me.

I am trying to use numpy histogram2d on 2 arrays each of size 55812. When I run the command np.histogram2d(x,y), I get the following error:

np.histogram2d(np.array(nlx_angle[50000:55000]),np.array(nlx_speed[50000:55000]), bins=(100,100))
File "C:\Anaconda2\lib\site-packages\numpy\lib\twodim_base.py", line 714, in histogram2d
hist, edges = histogramdd([x, y], bins, range, normed, weights)
File "C:\Anaconda2\lib\site-packages\numpy\lib\function_base.py", line 802, in histogramdd 
decimal = int(-log10(mindiff)) + 6

ValueError: cannot convert float NaN to integer

I have already removed all the NaN from the data. Also, the answer to the question (link above) suggested using a subset of data, but for my application, I need to use the entire data. I am using numpy version 1.11.0

Thanks for the help!

EDIT 1

I used np.where(nlx_angle==np.nan) and np.where(nlx_speed==np.nan) to check for NaN and all it returned is (array([], dtype=int64), array([], dtype=int64))

Community
  • 1
  • 1
deathracer
  • 305
  • 1
  • 20
  • What are the min and max of `nlx_angle[50000:55000]` and `nlx_speed[50000:55000]`? Check with `print(np.min(nlx_angle[50000:55000]))`, etc. – Warren Weckesser May 06 '17 at 15:17
  • Pretty hard to debug data we don't have. But are you absolutely certain you filtered out the `NaN`s properly? Can we see how you filtered them out? Seems like the error is pretty clear: it can't convert the float `NaN` to an integer. – Matt Messersmith May 06 '17 at 15:25
  • 1
    Your issue isn't NaNs in your input, the issue is negative numbers in your input. Somewhere in there you're running through `log10`, which produces a NaN if you give it a negative number. – Scott Mermelstein May 06 '17 at 17:19

0 Answers0