Python: Index Error: List Index out of range

Python: Index Error: List Index out of range



So I am running a program with two threads: One collecting Data and the other processing it. The problem is that after a certain amount of data collected and processed I get the error



File "...", line 54, in get_ratio
alpha=fft_avg_mod[d]
Index Error: List Index out of range



Even though I'm emptying the lists after every iteration as shown in the code. Appreciate any help or ideas


def get_data(q):
mindwaveDataPointReader = MindwaveDataPointReader()
mindwaveDataPointReader.start()

data=
while(1):
dataPoint = mindwaveDataPointReader.readNextDataPoint()
if (dataPoint.__class__ is RawDataPoint):
data.append(dataPoint)
q.put(data) #data keeps going into the queue

def get_ratio(q):
M = [,,,,,,,]
fft_avg =
fft_avg_mod =
#loop to cover all the data
j=0
k=0
l=0

while(1):
data = q.get()
if k > 7 :
fft_avg[:] = #emptying
fft_avg_mod[:] =
fft_avg = [(l1+l2+l3+l4+l5+l6+l7+l8)/8 for l1,l2,l3,l4,l5,l6,l7,l8 in zip(M[0],M[1],M[2],M[3],M[4],M[5],M[6],M[7])]
fft_avg_mod = [ abs(x) for x in fft_avg]


if fft_avg_mod:
d=random.randint(8,14)
e=random.randint(14,20)
alpha=fft_avg_mod[d] #THE ERROR
beta=fft_avg_mod[e]
ratio=beta/alpha
print 'ratio' , ratio
f=k%8
M[f] = np.fft.fft(data[j:j+32])
j = j + 32
k = k + 1


if __name__ == '__main__':

q = Queue.Queue(maxsize=0)

try:
threadLock = th.Lock()
threads=
thread1=th.Thread( target=get_data, args=(q,))
thread2=th.Thread( target=get_ratio, args=(q,))
thread1.start()
print 'T1 started'
time.sleep(10)
thread2.start()
print 'T2 started'
threads.append(thread1)
threads.append(thread2)
for t in threads:
t.join()
except:
print "Error: unable to start thread"





Please show the full traceback.
– roganjosh
Aug 25 at 8:52





@roganjosh Just edited the post
– Mohamed Belahcen
Aug 25 at 8:57





I suggest you learn some debugging right now. Catch that IndexError. Print out fft_avg_mod. Print out d. See why the error was raised.
– timgeb
Aug 25 at 8:58


IndexError


fft_avg_mod


d





@timgeb I agree. I will do that
– Mohamed Belahcen
Aug 25 at 9:03









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế