Search code examples
pythonpandasmnist

What does matrix[x] for different x indicate?


While using the MNIST datasetfrom kaggle,i have noticed that all the tutorials use mnist[x] for different values of x to retrieve different pictures.

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

mnist=pd.read_csv(r"(dir of dataset)").values
img=mnist[1]
img.shape=(28,28)
plt.imshow(img)
plt.show()

My doubt is what mnist[1] retrieves,also i have noticed that mnist[-1] also works,so that is why i am confused.


Solution

  • In Python, a matrix is just an array of array. Notice the second "array" I mentioned here could be another "matrix".

    So your "matrix[x]" simply means the (x+1)th element of your object.


    In case of the matrix for a dataset, mostly the first dimension of the matrix would be the sample id.

    So your "matrix[x]" means the argument array of the (x+1)th sample.