


import numpy as np
from PIL import Image
def 							__lowerCamelCase		(					UpperCAmelCase_		:						np.ndarray					,    UpperCAmelCase_		:						int					,    UpperCAmelCase_		:						int		):




      """simple docstring"""





      a		:Any									=			np.array(UpperCAmelCase_		)
      if arr.shape[0] != arr.shape[1]:
            raise ValueError('''The input array is not a square matrix'''		)
      a		:Optional[int]									=			0
      a		:Tuple									=			0
      a		:Any									=			0
      a		:Tuple									=			0

      # compute the shape of the output matrix
      a		:Union[str, Any]									=			(arr.shape[0] - size) // stride + 1
      # initialize the output matrix with zeros of shape maxpool_shape
      a		:int									=			np.zeros((maxpool_shape, maxpool_shape)		)

      while i < arr.shape[0]:
            if i + size > arr.shape[0]:
                  # if the end of the matrix is reached, break
                  break
            while j < arr.shape[1]:
                  # if the end of the matrix is reached, break
                  if j + size > arr.shape[1]:
                        break
                  # compute the maximum of the pooling matrix
                  a		:Tuple									=			np.max(arr[i : i + size, j : j + size]		)
                  # shift the pooling matrix by stride of column pixels
                  j += stride
                  mat_j += 1

            # shift the pooling matrix by stride of row pixels
            i += stride
            mat_i += 1

            # reset the column index to 0
            a		:List[str]									=			0
            a		:str									=			0

      return updated_arr
def 							__lowerCamelCase		(					UpperCAmelCase_		:						np.ndarray					,    UpperCAmelCase_		:						int					,    UpperCAmelCase_		:						int		):




      """simple docstring"""





      a		:List[Any]									=			np.array(UpperCAmelCase_		)
      if arr.shape[0] != arr.shape[1]:
            raise ValueError('''The input array is not a square matrix'''		)
      a		:List[str]									=			0
      a		:Optional[Any]									=			0
      a		:Any									=			0
      a		:List[Any]									=			0

      # compute the shape of the output matrix
      a		:Optional[int]									=			(arr.shape[0] - size) // stride + 1
      # initialize the output matrix with zeros of shape avgpool_shape
      a		:Dict									=			np.zeros((avgpool_shape, avgpool_shape)		)

      while i < arr.shape[0]:
            # if the end of the matrix is reached, break
            if i + size > arr.shape[0]:
                  break
            while j < arr.shape[1]:
                  # if the end of the matrix is reached, break
                  if j + size > arr.shape[1]:
                        break
                  # compute the average of the pooling matrix
                  a		:Tuple									=			int(np.average(arr[i : i + size, j : j + size]		)		)
                  # shift the pooling matrix by stride of column pixels
                  j += stride
                  mat_j += 1

            # shift the pooling matrix by stride of row pixels
            i += stride
            mat_i += 1
            # reset the column index to 0
            a		:Union[str, Any]									=			0
            a		:int									=			0

      return updated_arr


# Main Function
if __name__ == "__main__":
     from doctest import testmod

     testmod(name='''avgpooling''', verbose=True)

     # Loading the image
     snake_case							:       str										=	Image.open('''path_to_image''')

     # Converting the image to numpy array and maxpooling, displaying the result
     # Ensure that the image is a square matrix

     Image.fromarray(maxpooling(np.array(image), size=3, stride=2)).show()

     # Converting the image to numpy array and averagepooling, displaying the result
     # Ensure that the image is a square matrix

     Image.fromarray(avgpooling(np.array(image), size=3, stride=2)).show()









from __future__ import annotations

from typing import Any







class 						_snake_case    ( _snake_case				):
 pass







class 						_snake_case    :




 def __init__(						self   ,    _lowerCamelCase       ):
       a		:Any									=			data
       a		:Node | None									=			None




 def __iter__(						self       ):
       a		:Dict									=			self
       a		:Optional[int]									=			[]
       while node:
             if node in visited:
                   raise ContainsLoopError
             visited.append(_lowerCamelCase       )
             yield node.data
             a		:str									=			node.next_node




 @property
 def 			SCREAMING_SNAKE_CASE__							(						self       ):
       try:
             list(self       )
             return False
       except ContainsLoopError:
             return True


if __name__ == "__main__":
     snake_case							:       int										=	Node(1)
     snake_case							:       int										=	Node(2)
     snake_case							:       Optional[int]										=	Node(3)
     snake_case							:       List[str]										=	Node(4)
     print(root_node.has_loop)  # False
     snake_case							:       Optional[Any]										=	root_node.next_node
     print(root_node.has_loop)  # True

     snake_case							:       Dict										=	Node(5)
     snake_case							:       List[Any]										=	Node(6)
     snake_case							:       Optional[int]										=	Node(5)
     snake_case							:       Union[str, Any]										=	Node(6)
     print(root_node.has_loop)  # False

     snake_case							:       Tuple										=	Node(1)
     print(root_node.has_loop)  # False





