Python "TypeError: numpy.float64 object cannot be interpreted as an integer"

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]*np.pi/180)
                pyd[i,j]=y[i]-(delta*j)*np.cos(s[i]*np.pi/180)

    else:
        for j in range((N[i]-1)/2):
                pxd[i,j]=x[i]-(delta*j)*np.sin(s[i]*np.pi/180)
                pyd[i,j]=y[i]-(delta*j)*np.cos(s[i]*np.pi/180)     

Does anyone have an idea to solve this problem? Are these codes successful?

Thanks
Jeremy

+13
source share
3 answers
N=np.floor(np.divide(l,delta))
...
for j in range(N[i]/2):

N[i]/2will float64, but range()expects an integer. Just leave a challenge

for j in range(int(N[i]/2)):
+12
source

I came here with the same mistake, but with a different origin.

This is caused by an unsupported floating point index in 1.12.0 and later, even if the code should be considered valid.

Type expected int, notnp.float64

Solution: try installing numpy 1.11.0

sudo pip install -U numpy==1.11.0.
+4
source

    samples = np.append(np.zeros(np.floor(frameSize/2.0)), sig)

, :

samples = np.append(np.zeros(np.floor(int(frameSize/2.0))),sig)

:

    samples = np.append(np.zeros(int(frameSize/2.0)),sig)

. Numpy , , 1.15.4. ?

0

Source: https://habr.com/ru/post/1542976/


All Articles