unencountered error in FFT python

MRAB python at mrabarnett.plus.com
Sat Jan 30 14:08:03 EST 2010


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]




More information about the Python-list mailing list