def max_pool(x):
    """Return maximum in groups of 2x2 for a N,h,w image"""
N, h, w = x.shape
x = x.reshape(N, h / 2, 2, w / 2, 2).swapaxes(2, 3).reshape(N, h / 2, w / 2, 4)
return np.amax(x, axis=3)
Increasing speed of a pure Numpy/Scipy convolutional neural network implementation