[PYTHON] MNIST matrix display

python==3.7.9 Keras==2.2.4 tensorflow==1.13.1

Display mnist as an image


import urllib.request
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np


#prox = urllib.request.build_opener()
#urllib.request.install_opener(prox)


from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()


plt.imshow(x_train[0])

image.png

Display in matrix

In normal print, the matrix format is omitted and it is crushed. Make it easier to see by specifying the number of characters to be displayed in one line in linewidth

np.set_printoptions(linewidth = 115, precision = 1)

print(x_train[0])

It can be displayed in 115 characters including spaces.

image.png

that's all

Recommended Posts

MNIST matrix display
Matrix multiplication