After some sleuthing, I think I’ve found the issue. Since you are using Python 3, the division in line
j = idx / size is resulting in
j being a float, and when you use
int(j*h) it is turning it into an integer differently than would have happened in the initial division line. Try
j = idx // size to see what happens there. I believe that should fix your issue. I don’t have a Python 3 environment myself to test it on, but when I change the division to make j a float I get the same error that you do.