如何修复IndexError:循环中到标量变量的索引无效

时间:2019-05-07 09:31:39

标签: python python-2.7

为了首先实现DTW,我需要从中提取时间序列(像素序列) 每个图像。

当图像数量小于或等于55时,程序正常运行;但当图像数量大于或等于55时,程序会显示:

Traceback (most recent call last):
   File "tttm-1.py", line 26, in <module>
     for n in arr: list.append (n [0] [0])
IndexError: invalid index to scalar variable. 

为什么?

data = {}
for fn in range(1,1958):
    if fn==1:
        img = Image.open(r'C:\Users\admin\Desktop\image.PNG')

    else:
        img = Image.open(r'C:\Users\admin\Desktop\photo\{0}.jpg'.format(fn))
    arr = array(img)
    list = []
    for n in arr: list.append(n[0][0])
    for n in arr: list.append(n[0][1])
    for n in arr: list.append(n[0][2])
    data[fn] = list

0 个答案:

没有答案