0

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()
2
  • Your data is 4-dimensional. imshow requires 2- or 3-dimensional data. matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.imshow.html Commented Dec 27, 2020 at 18:20
  • Where oh where did the error occur. Don't just show code and an error summary! Commented Dec 27, 2020 at 19:09

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

As I understand the"20000" is the number of images in file. But thank you I'll try
Yes, you can treat that 4d array as a list of 20000 RGB images, and plot them separately use their indices.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.