Reputation: 9
I want to check my data and see images containing in images.npy
. How to solve that type of error?
TypeError: Invalid shape (20000, 48, 48, 3) for image data
Code:
import numpy as np
from matplotlib import pyplot as plt
images = np.load('images.npy')
plt.imshow(images)
plt.show()
Upvotes: 0
Views: 140
Reputation: 786
Try: (from https://matplotlib.org/3.3.3/tutorials/introductory/images.html)
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('images.npy')
imgplot = plt.imshow(img[0])#plot the first -- notice you are trying to plot 20k images, not 1
Upvotes: 0
Reputation: 1232
You cannot plot a 4d array that way. Try to split the first dimension 20000 into individual RGB images and then plot them using plt.subplots
instead.
Upvotes: 1