The below code is a max pooling algorithm being used in a CNN. The issue I've been facing is that it is offaly slow given a high number of feature maps. The reason for its slowness is quite obvious-- the computer must perform tens of thousands of iterations on each feature map. So, how do we decrease the computational complexity of the algorithm?
('inputs' is a numpy array which holds all the feature maps and 'pool_size' is a tuple with the dimensions of the pool.)
def max_pooling(inputs, pool_size): feature_maps =  for feature_map in range (len(inputs)): feature_maps.append() for i in range (0, len(inputs[feature_map]) - pool_size, pool_size): for j in range (0, len(inputs[feature_map]) - pool_size, pool_size): feature_maps[-1].append(np.array(max((inputs[feature_map][j:j+pool_size, i:i+pool_size]).flatten()))) return feature_maps