Python 3.x TypeError:打印图像时图像数据的形状(100、100、1)无效

Python 3.x TypeError:打印图像时图像数据的形状(100、100、1)无效,python-3.x,tensorflow,matplotlib,Python 3.x,Tensorflow,Matplotlib,我试图用100100,1来绘制图像,但得到了这样一个错误 TypeError: Invalid shape (100, 100, 1) for image data 这是密码 sample_training_images, _ = next(traindata) def plotImages(images_arr): fig, axes = plt.subplots(1, 5, figsize=(20,20)) axes = axes.flatten() for img

我试图用100100,1来绘制图像,但得到了这样一个错误

TypeError: Invalid shape (100, 100, 1) for image data
这是密码

sample_training_images, _ = next(traindata)
def plotImages(images_arr):
    fig, axes = plt.subplots(1, 5, figsize=(20,20))
    axes = axes.flatten()
    for img, ax in zip( images_arr, axes):
        ax.imshow(img)
        ax.axis('off')
    plt.tight_layout()
    plt.plot(images_arr)
    plt.show()

plotImages(sample_training_images[:5])

img
替换为
img[:,:,0]

 ax.imshow(img[:,:,0], cmap='gray')

并可能删除
plt.plot(images\u arr)
img
替换为
img[:,:,0]

 ax.imshow(img[:,:,0], cmap='gray')

而且可能会删除plt.plot(images\u arr)

仍然有相同的错误,我删除了plt.plot(images\u arr)并将plt.show()更改为您的答案。绘图图像中指出了错误line@SmurfAgain尝试
plt.imshow(images\u arr[:,:,0],cmap='gray')
。plotImages(sample\u training\u images[:5]中指出了错误由于同样的错误,我尝试用您的答案更改plt.show,但是still@SmurfAgain尝试新的更新。如果它不起作用,你需要用更多的细节更新你的问题,我也会删除这个答案。OK,我会跳过绘图部分,没有必要谢谢你的回答。仍然有相同的错误,我会删除plt.plot(image\u arr)并将plt.show()更改为您的答案。错误在绘图图像中指出line@SmurfAgain尝试
plt.imshow(images\u arr[:,:,0],cmap='gray')
。plotImages(sample\u training\u images[:5]中指出了错误由于同样的错误,我尝试用您的答案更改plt.show,但是still@SmurfAgain试试新的更新。如果它不起作用,你需要用更多的细节更新你的问题,我也会删除这个答案。好的,我跳过情节部分,没有必要谢谢你的回答