In [1]:
import numpy as np
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Convolution2D, MaxPooling2D
from keras.utils import np_utils
from PIL import Image
from numpy import array
import math


Using Theano backend.

In [2]:
#Loading the training and testing data
(X_train, y_train), (X_test, y_test) = mnist.load_data()

In [3]:
img = Image.fromarray(X_train[0])
img.show()
print(y_train[0])


5

In [4]:
no_of_examples = 71

In [5]:
new_im = Image.new('RGB', (280,28))
concat_img = Image.new('RGB', (280,int(math.ceil(no_of_examples/10)*28)))

In [6]:
x_offset = 0
concat_x_offset = 0

In [7]:
for i in range(0,no_of_examples):
    img = Image.fromarray(X_train[i])
    new_im.paste(img, (x_offset,0))
    x_offset += img.size[0]
    if ((i%10==0 and i!=0) or (i == no_of_examples-1)):
        #new_im.show()
        #concat_img = new_im
        concat_img.paste(new_im,(0,concat_x_offset))
        concat_x_offset += new_im.size[1]
        new_im = Image.new('RGB', (280,28))
        x_offset = 0

In [8]:
concat_img.show()

In [ ]: