TypeError: Invalid shape (100, 100, 1) for image data When plot image

Viewed 6169

I try to plot Images with 100,100,1 but got an error like this

TypeError: Invalid shape (100, 100, 1) for image data

here is the code

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])
1 Answers

Replace img with img[:,:,0]:

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

And probably remove the plt.plot(images_arr)

Related