Smurf Again
Smurf Again

Reputation: 359

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

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

Upvotes: 3

Views: 10579

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150735

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

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

And probably remove the plt.plot(images_arr)

Upvotes: 8

Related Questions