import numpy as np for i in range(len(x)): if (np.floor(N[i]/2)==N[i]/2): for j in range(N[i]/2): pxd[i,j]=x[i]-(delta*j)*np.sin(s[i]*) pyd[i,j]=y[i]-(delta*j)*np.cos(s[i]*) else: for j in range((N[i]-1)/2): pxd[i,j]=x[i]-(delta*j)*np.sin(s[i]*) pyd[i,j]=y[i]-(delta*j)*np.cos(s[i]*) Does anyone has an idea of solving this problem? Running these codes successfully?
16 Answers
N=np.floor(np.divide(l,delta)) ... for j in range(N[i]/2): N[i]/2 will be a float64 but range() expects an integer. Just cast the call to
for j in range(int(N[i]/2)): 2I came here with the same Error, though one with a different origin.
It is caused by unsupported float index in 1.12.0 and newer numpy versions even if the code should be considered as valid.
An int type is expected, not a np.float64
Solution: Try to install numpy 1.11.0
sudo pip install -U numpy==1.11.0. 0I had the same problems when I was training a retained object detection model (faster RCNN) and this worked for me perfectly:
pip uninstall pycocotools pip install pycocotools-windows 1Similar situation. It was working. Then, I started to include pytables. At first view, no reason to errors. I decided to use another function, that has a domain constraint (elipse) and received the following error:
TypeError: 'numpy.float64' object cannot be interpreted as an integer or
TypeError: 'numpy.float64' object is not iterable The crazy thing: the previous function I was using, no code changed, started to return the same error. My intermediary function, already used was:
def MinMax(x, mini=0, maxi=1) return max(min(x,mini), maxi) The solution was avoid numpy or math:
def MinMax(x, mini=0, maxi=1) x = [x_aux if x_aux > mini else mini for x_aux in x] x = [x_aux if x_aux < maxi else maxi for x_aux in x] return max(min(x,mini), maxi) Then, everything calm again. It was like one library possessed max and min!
While I appreciate this is not the OP's problem, I just had this error message for a very different reason and this is the top result so I'm posting my problem and resolution here.
I had this code:
x = np.ndarray([1.0, 2.0, 3.0], dtype=np.float_) Notice the subtle mistake? ndarray is the numpy array class, but you usually don't construct it directly. Instead you use the array() helper function:
x = np.array([1.0, 2.0, 3.0], dtype=np.float_) Switching to the second form solved my problem.
This problem may occur when we use an old version of numpy. In my case, I was using 1.18.5. I upgraded to 1.19.5 and the fail finished.
After this, if you are using Jupyter, you shall shutdown Kernell.