1
只是一個簡短的邏輯謎題:我試圖實現4個主計數器。在每個主計數器中都有子計數器。我通過創建一個2D列表來完成這項工作。如何初始化,然後追加到空的2D列表?
所以當觸發器被收集時,它會在每個主計數器中附加一個子計數器並允許它開始計數。例如,在第4個主計數器中,可以有不超過4個子計數器,並且每個子計數器只能存在240個週期(因此是窗口條件)。在第二主計數器,只能有2子計數器和每個櫃檯只能算25個時鐘週期
到目前爲止,我有這樣的:
def l1a(self):
for x in xrange(len(self.counter)) :
self.counter[x].append([0])
"Triggered"
print self.counter
def counterReset(self):
for j in xrange(len(self.counter)):
print self.counter
for k in xrange(len(self.counter[j])):
print self.counter[j][k]
if ((self.counter[j][k])/self.window[j]) == 1:
self.counter[j].pop(k) #delete counter
print self.counter
#print self.counter
def triggerRules(self):
breakMe = False
while breakMe == False:
for i in xrange(len(self.counter)):
if len(self.counter[i]) > i:
breakMe = True
break
if breakMe == False:
self.l1a()
def triggerClk(self):
for i in xrange(len(self.counter)):
for j in xrange(len(self.counter[i])):
self.counter[i][j] += 1
def myClk(self):
self.counterReset()
self.clk += 1
self.triggerClk()
nRand = random.randrange(0, self.max_word)
if nRand < self.frequency :
#print "Trying trigger"
self.triggerRules()
但它只是給我的輸出:
[[[0]], [[0]], [[0]], [[0]]]
[[[0]], [[0]], [[0]], [[0]]]
[0]
Traceback (most recent call last):
File "mp7trigsim.py", line 49, in <module>
if __name__ == '__main__':main()
File "mp7trigsim.py", line 27, in main
trig = TriggerGen(i, max_word, clkCycles)
File "TriggerGen.py", line 23, in __init__
self.myClk()
File "TriggerGen.py", line 60, in myClk
self.counterReset()
File "TriggerGen.py", line 37, in counterReset
if ((self.counter[j][k])/self.window[j]) == 1:
TypeError: unsupported operand type(s) for /: 'list' and 'int'
我如何得到它,所以它只是初始化4個主計數器,然後讓我追加並彈出它們?
我想我需要開始:
[[0], [0], [0], [0]]
,並最終設想一下,如果所有的櫃檯一分地:
[[0,1], [1,12,1,13], [11,24,5,2], [22,43,24,56]]
我敢肯定,這微妙的東西我丟失的?
謝謝,如果您覺得這是一個格式良好的問題,請1up – fiz 2015-02-10 13:26:02