Fun python 3.2 one-liner
Giacomo Boffi
giacomo.boffi at polimi.it
Tue Apr 5 01:36:53 EDT 2011
Chris Angelico <rosuav at gmail.com> writes:
>> def f(x,n,w): return x if n==1 else\
>> (lambda x0=f(x[::2],n/2,w[::2]),\
>> x1=f(x[1::2],n/2,w[::2]): reduce(lambda a,b: a+b ,\
>> zip(*[(x0[k]+w[k]*x1[k],\
>> x0[k]-w[k]*x1[k])\
>> for k in range(n/2)])))()
> What sort of parameters does this take? So far all I can figure out
> is that n is an integer and x and w are sliceables, but I'm not sure
> whether x and w should be strings or arrays.
def direct_fft(x,n):
return f(x,n,[exp(-2*pi*1j*k/n) for k in range(n/2)])
def inverse_fft(x,n):
return [x/n for x in f(x,n,[exp(+2*pi*1j*k/n) for k in range(n/2)])]
--
le mie sacrosante questioni di principio
VS gli sciocchi puntigli di quel cretino del mio vicino
More information about the Python-list
mailing list