unencountered error in FFT python
uche
uraniumore238 at gmail.com
Sat Jan 30 20:18:51 CET 2010
On Jan 30, 2:08 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> uche wrote:
> > Hi,
> > I have the following FFT python code and it doesn't seem to compile
> > correctly. To run it, please create a file called output.csv with
> > 1,2,3,4,5,6,7,8. simply run the main function. I get an error such as
> > the following:
>
> > x[a], x[b] = x[(a)] + W[(n % N)] * x[(b)], x[(a)] - W[(n % N)] * x
> > [(b)]
> > TypeError: list indices must be integers, not float
>
> > How can I fixe this problem ? I have tried puttin int on all of the
> > variables, but I don't think that is the intension of the person who
> > wore the original code.
>
> Which version of Python are you using? In Python 3 the division operator
> '/' returns a float, whereas in Python 2 it returns an int if both
> operands are int. In Python 3 the int division operator is '//', which
> is also accepted in recent versions of Python 2.
>
> [snip]
>
> > os.path.exists("input.csv")
>
> > fin=open('input.csv', 'r')
>
> > for line in fin: #read the line from the file
>
> > array=line.split(',')
>
> These lines should be indented more:
>
> > for a in range(len(array)): #convert into integers
>
> > array2.append((array[a]))
>
> array2.append(int(array[a]))
>
> [snip]
Thanks, I just got this code from a site and trying to compile it.
it's just a nightmare!
I got another problem after changing / to // . Yes, I am using 3.1.
W.append(exp(sign * 2j * pi * i // N))
TypeError: can't take floor of complex number.
More information about the Python-list
mailing list