In [9]:
import keras as kr
import numpy as np
In [2]:
kr.datasets.mnist
Out[2]:
<module 'keras.datasets.mnist' from 'C:\\Users\\mclou\\Anaconda3\\lib\\site-packages\\keras\\datasets\\mnist.py'>
In [4]:
(x_train, y_train), (x_test, y_test) = kr.datasets.mnist.load_data()
Downloading data from https://s3.amazonaws.com/img-datasets/mnist.npz
11493376/11490434 [==============================] - 2s 0us/step
In [10]:
type(x_train)
Out[10]:
numpy.ndarray
In [12]:
x_train.shape
Out[12]:
(60000, 28, 28)
In [13]:
x_train.dtype
Out[13]:
dtype('uint8')
In [14]:
np.uint8
Out[14]:
numpy.uint8
In [21]:
x_train[0][13][13]
Out[21]:
241
In [22]:
x_train[0][13][13].dtype
Out[22]:
dtype('uint8')
In [23]:
x_train[0][13][13].astype(np.int8)
Out[23]:
-15
In [24]:
y_train
Out[24]:
array([5, 0, 4, ..., 5, 6, 8], dtype=uint8)
In [27]:
y_train.dtype
Out[27]:
dtype('uint8')
In [47]:
x_train[0];
In [54]:
x = (x_train[0] > 0).astype(np.uint8).tolist()
In [55]:
''.join([''.join(i) for i in x])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-55-f2a9bb07165b> in <module>
----> 1 ''.join([''.join(i) for i in x])

<ipython-input-55-f2a9bb07165b> in <listcomp>(.0)
----> 1 ''.join([''.join(i) for i in x])

TypeError: sequence item 0: expected str instance, int found
In [52]:
for l in [['0' if i else '.' for i in j] for j in x]:
    print(''.join(l))
............................
............................
............................
............................
............................
............000000000000....
........0000000000000000....
.......0000000000000000.....
.......00000000000..........
........0000000.00..........
.........00000..............
...........0000.............
...........0000.............
............000000..........
.............000000.........
..............000000........
...............00000........
.................0000.......
..............0000000.......
............00000000........
..........000000000.........
........0000000000..........
......0000000000............
....0000000000..............
....00000000................
............................
............................
............................
In [ ]: