gpt4 book ai didi

python - 索引错误: index 100 is out of bounds for axis 0 with size 8

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:42 24 4
gpt4 key购买 nike

我对 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,:])

我很感激一些帮助,因为我很困惑。

最佳答案

尝试做类似的事情

if (len(X_train >= i):
plt.imshow(X_train[i,0], 插值='最近')
print("标签:", Y_train[i,:])

避免这样的错误

关于python - 索引错误: index 100 is out of bounds for axis 0 with size 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55422705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com