閃光的問題,我在看下面的代碼Python中的[0] * x語法是做什麼的?
from __future__ import division
import math
import time
def dft(x, inverse = False, verbose = False) :
t = time.clock()
N = len(x)
inv = -1 if not inverse else 1
X =[0] * N
for k in xrange(N) :
for n in xrange(N) :
X[k] += x[n] * math.e**(inv * 2j * math.pi * k * n/N)
if inverse :
X[k] /= N
t = time.clock() - t
if verbose :
print "Computed","an inverse" if inverse else "a","DFT of size",N,
print "in",t,"sec."
return X
,我想知道(我不知道蟒蛇):
- 什麼是X = [0] * N行嗎?
- 爲什麼雙星號**?
謝謝大家的回答! – Paul 2011-05-15 12:17:38
你爲什麼不自己嘗試?例如,在你的解釋器外殼中有類似'>>> [0] * 10'的東西就足夠了...... – joaquin 2011-05-15 13:22:33