找出这段代码的bug:import numpy as np j=1j w=lambda n,k:np.cos(k*2*np.pi/n)+np.sin(k*2*np.pi/n)*j N=8 #0,1,2,3,4 buf=[0 for i in range(N)] print(len(buf)) def FFT(a:list,n,inv:bool): if n==1: return None m=int(n/2) i=0 while i<m: buf[i]=a[2*i] print('i',i,'buf:',i+m,',a:',2*i+1) buf[i+m]=a[2*i+1] i+=1 for i in range(n): a[i]=buf[i] b=a[:m-1] c=a[m:] b=FFT(b,m,inv) c=FFT(c,n,inv) a=b+c i=0 while i<m: x=w(n,i) buf[i]=a[i]+x*a[i+m] buf[i+m]=a[i]-x*a[i+m] i+=1 i=0 while i<n: a[i]=buf[i] i+=1 return a FFT(a=[1,2,3,4,5,6,7,8],n=8,inv=False)
时间: 2023-05-17 20:06:12 浏览: 68
这段代码存在一个语法错误,即缺少一个乘号。正确的代码应该是:
import numpy as np
j = 1j
w = lambda n,k: np.cos(k*2*np.pi/n) * np.sin(k*2*np.pi/n) * j
N = 8
阅读全文