<jupyter_start><jupyter_text>Pooling<jupyter_code>import numpy as np
def pooling_strided_naive(image, pool_size, stride, function):
    output_x = int((image.shape[0] - pool_size) / stride + 1) 
    output_y = int((image.shape[1] - pool_size) / stride + 1)
    output = np.zeros((output_x, output_y))

    # walk over output rows
    for i in range(output.shape[0]):
        # walk over output columns
        for j in range(output.shape[1]):
            image_x = i * stride
            image_y = j * stride
            image_x_end = image_x + pool_size
            image_y_end = image_y + pool_size
            output[i, j] = function(image[image_x:image_x_end,
                                           image_y:image_y_end])
    
    return output
image = np.array([
    [1, 3, 2, 1],
    [2, 9, 1, 1],
    [1, 3, 2, 3],
    [5, 6, 1, 2]
])
# Max pooling
pooling_strided_naive(image, 2, 2, np.max)
# Average pooling
pooling_strided_naive(image, 2, 2, np.mean)
image = np.array([
    [1, 3, 2, 1, 3],
    [2, 9, 1, 1, 5],
    [1, 3, 2, 3, 2],
    [8, 3, 5, 1, 0],
    [5, 6, 1, 2, 9]
])
pooling_strided_naive(image, 3, 1, np.max)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14371772805507746, 'fraction_numerical': 0.04561101549053356, 'mean_word_length': 2.39067055393586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '45494', 'license': 'MIT', 'n_tokens_mistral': 497, 'n_tokens_neox': 448, 'n_words': 117, 'path': 'deep-learning/Pooling.ipynb', 'repo_name': 'ashishpatel26/learning', 'size': '1162'}