In [1]:
from keras.datasets import cifar10
from keras.utils.np_utils import to_categorical
import numpy as np

from IPython import display
import matplotlib.pyplot as plt

% matplotlib inline
% config InlineBackend.figure_format = 'retina'


Using TensorFlow backend.

In [2]:
(X_train, y_train), (X_test, y_test) = cifar10.load_data()

In [3]:
print np.mean(X_train), np.std(X_train)
print np.mean(X_test), np.std(X_test)


120.707565124 64.1500758911
121.529154753 64.060970123

In [4]:
X_train_class_average = np.ndarray(shape=(10, X_train.shape[1], X_train.shape[2], X_train.shape[3]), dtype='float32')
X_train_class_average *= 0

for index in range(len(X_train)):
    y_class = y_train[index]
    X_train_class_average[y_class] += X_train[index]
    
    
X_train_class_average /= 5000.
for X_train_class in X_train_class_average:
    print np.mean(X_train_class)


142.366
116.698
119.406
116.232
111.775
117.394
106.562
118.89
133.476
124.277

In [7]:
plt.figure(figsize=(10, 4))
for i in range(10):
    plt.subplot(2, 5, i+1)
    img = X_train_class_average[i, :, : :]
    plt.imshow(img)
    plt.axis('off')
plt.tight_layout()
plt.show()



In [ ]: