Issue displaying mnist training images in console

Viewed 144

Heres my code from tutorial.

enter image description here

import tensorflow as tf
import numpy as np
from tensorflow import keras
print(tf.__version__)

#import the MNIST dataset 
mnist = tf.keras.datasets.fashion_mnist

#load training and testing sets
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()

import matplotlib.pyplot as plt
plt.imshow(training_images[0])

print(training_labels[0])
print(training_images[0])

The issue is, when I run it I get this output in the console. the image is cut in half right down the middle. For reference its supposed to look more like

enter image description here

you can see the image displays properly. I'm sure its just some dumb setting I'm missing.

I've tried messing with some of the properties for the command prompt window like window/buffer width, but nothing works so far.

2 Answers

I think the easiest thing for you to do is to save the output into a txt file in a formated way. For example:

np.savetxt("test.txt", training_images[0], fmt='%8.2f')

It's two print loops. You can try something of this sort:

t_images = training_images[0].tolist()

for image in t_images:
    for value in image:
        print('%4d'%(value), end='')

    print()

The %4d pads with 4 spaces.

This is how it looks: sample output

Related