Let's plot the average 1 image that we obtained in step 2:
pic=np.zeros((28,28)) pic2=np.copy(pic) for i in range(X_train1.shape[0]): pic2=X_train1[i,:,:] pic=pic+pic2 pic=(pic/X_train1.shape[0]) plt.imshow(pic)
In the preceding code, we initialized an empty picture that is 28 x 28 in dimension and took an average pixel value at the various pixel locations of images that have a label of 1 (the X_train1 object) by looping through all the values in the X_train1 object.
The plot of the average 1 image appears as follows:
It is to be noted that the more yellow (thick) the pixel is, the more often people have written on top of the pixel, and the less yellow (more blue/less thick) the pixel, the less often people have written on top of the pixel. Also, it is to be noted that the pixel in the middle is the yellowest/thickest (this is because most people would be writing over the middle pixels, irrespective of whether the whole digit is written in a vertical line or is slanted toward the left or right).