import numpy as np
from PIL import Image
def 		snake_case__	(		lowercase							,				lowercase							,				lowercase					):
   lowerCAmelCase_:							List[str]       =	np.array(lowercase					)
   if arr.shape[0] != arr.shape[1]:
      raise ValueError("The input array is not a square matrix"					)
   lowerCAmelCase_:							Dict       =	0
   lowerCAmelCase_:							Dict       =	0
   lowerCAmelCase_:							int       =	0
   lowerCAmelCase_:							Tuple       =	0

   # compute the shape of the output matrix
   lowerCAmelCase_:							Optional[int]       =	(arr.shape[0] - size) // stride + 1
   # initialize the output matrix with zeros of shape maxpool_shape
   lowerCAmelCase_:							List[Any]       =	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
         lowerCAmelCase_:							Dict       =	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
      lowerCAmelCase_:							List[Any]       =	0
      lowerCAmelCase_:							Optional[int]       =	0

   return updated_arr
def 		snake_case__	(		lowercase							,				lowercase							,				lowercase					):
   lowerCAmelCase_:							Tuple       =	np.array(lowercase					)
   if arr.shape[0] != arr.shape[1]:
      raise ValueError("The input array is not a square matrix"					)
   lowerCAmelCase_:							List[str]       =	0
   lowerCAmelCase_:							Any       =	0
   lowerCAmelCase_:							List[Any]       =	0
   lowerCAmelCase_:							Optional[Any]       =	0

   # compute the shape of the output matrix
   lowerCAmelCase_:							List[Any]       =	(arr.shape[0] - size) // stride + 1
   # initialize the output matrix with zeros of shape avgpool_shape
   lowerCAmelCase_:							Union[str, Any]       =	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
         lowerCAmelCase_:							Any       =	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
      lowerCAmelCase_:							Dict       =	0
      lowerCAmelCase_:							Optional[Any]       =	0

   return updated_arr


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

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

 # Loading the image
 a  :      List[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()
class 					_lowercase    :






    '''simple docstring'''




    def __init__(    self ):
       lowerCAmelCase_:							dict[str, TrieNode]       =	{}  # Mapping from char to TrieNode
       lowerCAmelCase_:							str       =	False




    def      _a    (    self       ,						lowerCamelCase__ ):
       for word in words:
          self.insert(lowerCamelCase__ )




    def      _a    (    self       ,						lowerCamelCase__ ):
       lowerCAmelCase_:							Union[str, Any]       =	self
       for char in word:
          if char not in curr.nodes:
             lowerCAmelCase_:							List[Any]       =	TrieNode()
          lowerCAmelCase_:							Optional[Any]       =	curr.nodes[char]
       lowerCAmelCase_:							Dict       =	True




    def      _a    (    self       ,						lowerCamelCase__ ):
       lowerCAmelCase_:							Optional[Any]       =	self
       for char in word:
          if char not in curr.nodes:
             return False
          lowerCAmelCase_:							Dict       =	curr.nodes[char]
       return curr.is_leaf




    def      _a    (    self       ,						lowerCamelCase__ ):

       def _delete(lowerCamelCase__       ,						lowerCamelCase__       ,						lowerCamelCase__ ) -> bool:
          if index == len(lowerCamelCase__ ):
             # If word does not exist
             if not curr.is_leaf:
                return False
             lowerCAmelCase_:							List[str]       =	False
             return len(curr.nodes ) == 0
          lowerCAmelCase_:							Union[str, Any]       =	word[index]
          lowerCAmelCase_:							Optional[int]       =	curr.nodes.get(lowerCamelCase__ )
          # If char not in current trie node
          if not char_node:
             return False
          # Flag to check if node can be deleted
          lowerCAmelCase_:							List[Any]       =	_delete(lowerCamelCase__       ,						lowerCamelCase__       ,						index + 1 )
          if delete_curr:
             del curr.nodes[char]
             return len(curr.nodes ) == 0
          return delete_curr

       _delete(self       ,						lowerCamelCase__       ,						0 )





def 		snake_case__	(		lowercase							,				lowercase					):
   if node.is_leaf:
      print(lowercase							,				end=" "					)

   for key, value in node.nodes.items():
      print_words(lowercase							,				word + key					)
def 		snake_case__	(		):
   lowerCAmelCase_:							Any       =	"banana bananas bandana band apple all beast".split()
   lowerCAmelCase_:							Optional[Any]       =	TrieNode()
   root.insert_many(lowercase					)
   # print_words(root, "")
   assert all(root.find(lowercase					) for word in words					)
   assert root.find("banana"					)
   assert not root.find("bandanas"					)
   assert not root.find("apps"					)
   assert root.find("apple"					)
   assert root.find("all"					)
   root.delete("all"					)
   assert not root.find("all"					)
   root.delete("banana"					)
   assert not root.find("banana"					)
   assert root.find("bananas"					)
   return True
def 		snake_case__	(		lowercase							,				lowercase					):
   print(str(lowercase					)							,				"works!" if passes else "doesn't work :("					)
def 		snake_case__	(		):
   assert test_trie()
def 		snake_case__	(		):
   print_results("Testing trie functionality"							,				test_trie()					)


if __name__ == "__main__":
 main()