Help find a bug in the code

IndexError: list index out of range
I can’t understand why this error is being called.

import numpy as np
import random

wn1 = 2
epochs = 10
st_s1 = np.random.rand(10,9)
st_t1 = np.random.rand(10,1)
len_st = len(st_s1)
b = len_st-wn1

for epoch in range(epochs):
    shuffle_list = list(range(1, b))
    random.shuffle(shuffle_list)
    for wn_start in range(b):
        wn_all2 = []
        los_l = []
        shuffle_temp = shuffle_list[wn_start]
        los_l.append(st_t1[shuffle_temp+wn1])
        wn_all2.append(st_s1[shuffle_temp:shuffle_temp+wn1,3:6])

Hi @slavavs,

Here you declare a list of length 7:

    shuffle_list = list(range(1, b))

So in the inner loop you should iterate of range(b-1) and not range(b).

1 Like