IndexError:索引100超出轴8的大小8

时间:2019-03-29 17:27:54

标签: python indexing

我是Python的新手。我收到以下索引错误:

Traceback (most recent call last): File "Pride.py", line 109, in <module>
plt.imshow(X_train[i,0], interpolation='nearest')
IndexError: index 100 is out of bounds for axis 0 with size 8 

代码如下:

print('X_train shape:', X_train.shape)
print(X_train.shape[0], 'train samples')
print(X_test.shape[0], 'test samples')

# convert class vectors to binary class matrices
Y_train = np_utils.to_categorical(y_train, nb_classes)
Y_test = np_utils.to_categorical(y_test, nb_classes)

i = 100
plt.imshow(X_train[i,0], interpolation='nearest')
print("label : ", Y_train[i,:]) 

我很困惑,不胜感激。

1 个答案:

答案 0 :(得分:0)

尝试做类似的事情

if (len(X_train >= i): plt.imshow(X_train[i,0], interpolation='nearest') print("label : ", Y_train[i,:])

避免此类错误