简体   繁体   English

如何一次显示一个多维数组中的所有图像?

[英]How to display all images from a single a multidimensional-array at once?

I have a multidimensional array (11, 28, 28) which consists of 11 images, each with 28*28 pixels. 我有一个多维数组(11, 28, 28) ,其中包含11张图像,每个图像具有28 * 28像素。

x_train_new_reshaped[0].shape

Out[8]: (11, 28, 28)

How can I display them all at once? 如何一次显示所有内容?

This results in: 结果是:

In:
image = x_train_new_reshaped[0]
plt.figure()
plt.imshow(image)
plt.show()


Out:
TypeError: Invalid dimensions for image data

This as well: 这也是:

In:
image = np.squeeze(x_train_new_reshaped[0])
plt.figure()
plt.imshow(image)
plt.show()

Out:
TypeError: Invalid dimensions for image data

Any help is appreciated. 任何帮助表示赞赏。

In case you want an image-plot as your code suggests, then the array should be 2D. 如果您希望按照代码提示使用图像绘图,则该数组应为2D。 Since you have multiple images stored in a 3D array, the easiest way would be to do a subplot for each image stored in your array and loop over them. 由于您在3D数组中存储了多个图像,所以最简单的方法是为数组中存储的每个图像做一个子图并在它们上循环。 With matplotlib you can find many examples how a subplot looks like, for example also here on stackoverflow: How do I get multiple subplots in matplotlib? 使用matplotlib,您可以找到许多子图样的示例,例如在stackoverflow上也是如此: 如何在matplotlib中获得多个子图?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM