def cnn_pool(pool_dim, convolved_features):
 num_images = convolved_features.shape[1]
 num_features = convolved_features.shape[0]
 convolved_dim = convolved_features.shape[2]
 assert ((convolved_dim % pool_dim) == 0), 'Pooling dimension is not an exact multiple of convolved dimension'
 pool_size = (convolved_dim / pool_dim)
 pooled_features = np.zeros(shape=(num_features, num_images, pool_size, pool_size), dtype=np.float64)
 for i in range(pool_size):
  for j in range(pool_size):
   pool = convolved_features[:, :, (i * pool_dim):((i + 1) * pool_dim), (j * pool_dim):((j + 1) * pool_dim)]
   pooled_features[:, :, i, j] = np.mean(np.mean(pool, 2), 2)
 return pooled_features

def cnn_pool ( pool_dim , convolved_features ) : num_images = convolved_features . shape [ 1 ] num_features = convolved_features . shape [ 0 ] convolved_dim = convolved_features . shape [ 2 ] assert ( ( convolved_dim % pool_dim ) == 0 ) , 'Pooling dimension is not an exact multiple of convolved dimension' pool_size = ( convolved_dim / pool_dim ) pooled_features = np . zeros ( shape = ( num_features , num_images , pool_size , pool_size ) , dtype = np . float64 ) for i in range ( pool_size ) : for j in range ( pool_size ) : pool = convolved_features [ : , : , ( i * pool_dim ) : ( ( i + 1 ) * pool_dim ) , ( j * pool_dim ) : ( ( j + 1 ) * pool_dim ) ] pooled_features [ : , : , i , j ] = np . mean ( np . mean ( pool , 2 ) , 2 ) return pooled_features
pools the given convolved features .