text_plain_output_1.png
import matplotlib.pyplot as plt

import numpy as np

train = np.loadtxt('../input/train.csv', delimiter=',', skiprows=1)

train_label = train[:, 0]
train_img = np.resize(train[:, 1:], (train.shape[0], 28, 28))

train_img.shape

fig = plt.figure(figsize=(20, 10))
for i, img in enumerate(train_img[0:5], 1):
    subplot = fig.add_subplot(1, 7, i)
    plt.imshow(img, cmap='gray');
    subplot.set_title('%s' % train_label[i - 1]);

fig = plt.figure(figsize=(20, 10))
for i, img in enumerate(train_g[:5], 1):
    subplot = fig.add_subplot(1, 7, i)
    plt.imshow(img, cmap='gray');
    subplot.set_title('%s' % train_label[i - 1]);
    subplot = fig.add_subplot(3, 7, i)
    plt.hist(train_theta[i - 1].flatten(),
             bins=16, weights=train_g[i - 1].flatten())

h, w = train_img.shape[1:]
cX, cY = (int(w * 0.5), int(h * 0.5))
segments = [(0, w, 0, cY), (0, w, cY, h), (0, cX, 0, h), (cX, w, 0, h)]

fig = plt.figure(figsize=(16, 4))
for num, i in enumerate(segments, 1):
    subplot = fig.add_subplot(1, 4, num)
    plt.imshow(train_img[1, i[0]:i[1], i[2]:i[3]], cmap='gray')