alexpleasehelpme
alexpleasehelpme

Reputation: 9

How to solve TypeError exception with matplotlib?

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

Answers (2)

Gaussian Prior
Gaussian Prior

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

TQCH
TQCH

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

Related Questions