首页 > 解决方案 > IndexError:索引 1040 超出轴 0 的范围,大小为 1040

问题描述

我试图理解一个项目的代码,我正在尝试编译它。所以我发现了这个问题。

cpt=0
for img in t :
    x = img_to_array(img)
    x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)
    X_train1[cpt,:,:] = x[0,:,:,:]
    cpt+=1

() 中的 IndexErrorTraceback(最近一次调用最后一次)

      4     x = np.expand_dims(x, axis=0)
      5     x = preprocess_input(x)
----> 6     X_train1[cpt,:,:] = x[0,:,:,:]
      7     cpt+=1

IndexError:索引 1040 超出轴 0 的范围,大小为 1040

标签: pythontensorflowkerasindex-error

解决方案


问题在于创建X_train1,您可能已经X_train1使用t.len() - 1create it witht.len()来创建


推荐阅读