Visualize MNIST dataset using OpenCV or Matplotlib/Pyplot

后端 未结 3 1075

i have MNIST dataset and i am trying to visualise it using pyplot. The dataset is in cvs format where each row is one image of 784 pixels. i want to visualise it in

3条回答
  •  情深已故
    2021-02-19 13:47

    Importing necessary packages

    import pandas as pd
    import matplotlib.pyplot as plt
    import numpy as np
    

    Reading mnist train dataset ( which is csv formatted ) as a pandas dataframe

    s = pd.read_csv("mnist_train.csv")
    

    Converting the pandas dataframe to a numpy matrix

    data = np.matrix(s)
    

    The first column contains the label, so store it in a separate array

    output = data[:, 0]
    

    And delete the first column from the data matrix

    data = np.delete(data, 0, 1)
    

    The first row represents the first image, it is 28X28 image (stored as 784 pixels)

    img = data[0].reshape(28,28)
    
    # And displaying the image
    plt.imshow(img, cmap="gray")
    

提交回复
热议问题