






"""simple docstring"""





import numpy as np
from PIL import Image







def 	lowerCamelCase__			(				_lowerCamelCase			:						np.ndarray						,							_lowerCamelCase			:						int						,							_lowerCamelCase			:						int					) ->							np.ndarray:
  lowerCamelCase_       	=		np.array(_lowerCamelCase					)
  if arr.shape[0] != arr.shape[1]:
    raise ValueError('The input array is not a square matrix'					)
  lowerCamelCase_       	=		0
  lowerCamelCase_       	=		0
  lowerCamelCase_       	=		0
  lowerCamelCase_       	=		0

  # compute the shape of the output matrix
  lowerCamelCase_       	=		(arr.shape[0] - size) // stride + 1
  # initialize the output matrix with zeros of shape maxpool_shape
  lowerCamelCase_       	=		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_       	=		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_       	=		0
    lowerCamelCase_       	=		0

  return updated_arr







def 	lowerCamelCase__			(				_lowerCamelCase			:						np.ndarray						,							_lowerCamelCase			:						int						,							_lowerCamelCase			:						int					) ->							np.ndarray:
  lowerCamelCase_       	=		np.array(_lowerCamelCase					)
  if arr.shape[0] != arr.shape[1]:
    raise ValueError('The input array is not a square matrix'					)
  lowerCamelCase_       	=		0
  lowerCamelCase_       	=		0
  lowerCamelCase_       	=		0
  lowerCamelCase_       	=		0

  # compute the shape of the output matrix
  lowerCamelCase_       	=		(arr.shape[0] - size) // stride + 1
  # initialize the output matrix with zeros of shape avgpool_shape
  lowerCamelCase_       	=		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_       	=		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_       	=		0
    lowerCamelCase_       	=		0

  return updated_arr


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

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

  # Loading the image
  _SCREAMING_SNAKE_CASE   :							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()












"""simple docstring"""





def 	lowerCamelCase__			(				_lowerCamelCase			:						int = 10						,							_lowerCamelCase			:						int = 1000						,							_lowerCamelCase			:						bool = True					) ->							int:
  assert (
      isinstance(_lowerCamelCase						,							_lowerCamelCase					)
      and isinstance(_lowerCamelCase						,							_lowerCamelCase					)
      and isinstance(_lowerCamelCase						,							_lowerCamelCase					)
  ), "Invalid type of value(s) specified to function!"

  if min_val > max_val:
    raise ValueError('Invalid value for min_val or max_val (min_value < max_value)'					)
  return min_val if option else max_val







def 	lowerCamelCase__			(				_lowerCamelCase			:						int						,							_lowerCamelCase			:						int					) ->							int:
  return int((number_a + number_a) / 2					)







def 	lowerCamelCase__			(				_lowerCamelCase			:						int						,							_lowerCamelCase			:						int						,							_lowerCamelCase			:						int					) ->							None:
  assert (
      isinstance(_lowerCamelCase						,							_lowerCamelCase					) and isinstance(_lowerCamelCase						,							_lowerCamelCase					) and isinstance(_lowerCamelCase						,							_lowerCamelCase					)
  ), 'argument values must be type of "int"'

  if lower > higher:
    raise ValueError('argument value for lower and higher must be(lower > higher)'					)

  if not lower < to_guess < higher:
    raise ValueError(
        'guess value must be within the range of lower and higher value'					)

  def answer(_lowerCamelCase			:						int					) -> str:
    if number > to_guess:
      return "high"
    elif number < to_guess:
      return "low"
    else:
      return "same"

  print('started...'					)

  lowerCamelCase_       	=		lower
  lowerCamelCase_       	=		higher

  lowerCamelCase_       	=		[]

  while True:
    lowerCamelCase_       	=		get_avg(_lowerCamelCase						,							_lowerCamelCase					)
    last_numbers.append(_lowerCamelCase					)

    if answer(_lowerCamelCase					) == "low":
      lowerCamelCase_       	=		number
    elif answer(_lowerCamelCase					) == "high":
      lowerCamelCase_       	=		number
    else:
      break

  print(F'''guess the number : {last_numbers[-1]}'''					)
  print(F'''details : {last_numbers!s}'''					)







def 	lowerCamelCase__			(				) ->							None:
  lowerCamelCase_       	=		int(input('Enter lower value : '					).strip()					)
  lowerCamelCase_       	=		int(input('Enter high value : '					).strip()					)
  lowerCamelCase_       	=		int(input('Enter value to guess : '					).strip()					)
  guess_the_number(_lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase					)


if __name__ == "__main__":
  main()




