20201016のTensorFlowに関する記事は1件です。

MNISTの行列表示

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

mnistを画像表示する

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

行列で表示

通常のprintではmatrix形式が省略されてつぶれてしまうが
linewidthに一行に表示する文字数を指定することで見やすくする

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

print(x_train[0])

スペースを含み115文字で表示できる。

image.png

以上

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む