IndexError:索引248超出了轴0的大小为248的范围

时间:2017-04-14 07:07:06

标签: python

length = int(y.size/512) + 1  #length  5168
label_musicl = np.zeros(length)
lenth_beaat_frames = beats_frames.size # length 248
j = 0
for i in range(len(label_musicl)):
    if i == beats_frames[j]: 
        label_musicl[i] = 1
        j+=1

有我的代码,当我尝试运行代码时,Indexerror总是会发生。真的很喜欢,需要一些帮助.LOL

Traceback (most recent call last):
File "sftf.py", line 39, in <module>
if i == beats_frames[j]: 
IndexError: index 248 is out of bounds for axis 0 with size 248

1 个答案:

答案 0 :(得分:0)

这将有效:

for i in range(len(label_musicl)-1):

因为当你使用len()时它会给你绝对的长度数和python start中的索引0而不是1