[英]list index out of range in python 2.7
I need to create a program in python using fourier transform. 我需要使用傅立叶变换在python中创建一个程序。 It says: list index out of range,and I don;t understand why. 它说:列出索引超出范围,我不明白为什么。 The error is at these lines: 错误在以下几行:
Feven = fft([x[i] for i in xrange(0, n, 2)],n/2)
Fodd = fft([x[i] for i in xrange(1, n, 2)],n/2)
Have you tried separating the the list compilation from function call to find out the location the exception is thrown? 您是否尝试过将列表编译与函数调用分开,以找出引发异常的位置?
# assuming n <= len(x)
even = [x[i] for i in xrange(0, n, 2)]
Feven = fft(even,n/2)
You could also use slicing to get every second element in list: 您还可以使用切片来获取列表中的每个第二个元素:
even = x[::2]
odd = x[1::2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.