reshape an array of images

前端 未结 3 939
陌清茗
陌清茗 2021-01-19 06:15

I have 60000 train_images brought in as a shape (28,28,60000) matrix. It is a numpy.ndarray. I want to convert it to an array of 1 dimensional images, meaning each image is

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-19 06:31

    You can reshape train_images and verify it by plotting the images,

    Reshaping:

    train_features_images = train_images.reshape(train_images.shape[0],28,28) 
    

    Plotting images:

    import matplotlib.pyplot as plt
    def show_images(features_images,labels,start, howmany):
        for i in range(start, start+howmany):
            plt.figure(i)
            plt.imshow(features_images[i], cmap=plt.get_cmap('gray'))
            plt.title(labels[i])
        plt.show()
    show_images(train_features_images, labels, 1, 10)
    

提交回复
热议问题