
"""simple docstring"""




from __future__ import annotations

from PIL import Image

# Define glider example
A__							=   [
    [0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
]

# Define blinker example
A__							=   [[0, 1, 0], [0, 1, 0], [0, 1, 0]]




def  _lowerCAmelCase		(		_UpperCamelCase						):






  """simple docstring"""



  _lowercase:			List[Any]       =     []
  for i in range(len(_UpperCamelCase						)						):
    _lowercase:			Union[str, Any]       =     []
    for j in range(len(cells[i]						)						):
      # Get the number of live neighbours
      _lowercase:			Any       =     0
      if i > 0 and j > 0:
        neighbour_count += cells[i - 1][j - 1]
      if i > 0:
        neighbour_count += cells[i - 1][j]
      if i > 0 and j < len(cells[i]						) - 1:
        neighbour_count += cells[i - 1][j + 1]
      if j > 0:
        neighbour_count += cells[i][j - 1]
      if j < len(cells[i]						) - 1:
        neighbour_count += cells[i][j + 1]
      if i < len(_UpperCamelCase						) - 1 and j > 0:
        neighbour_count += cells[i + 1][j - 1]
      if i < len(_UpperCamelCase						) - 1:
        neighbour_count += cells[i + 1][j]
      if i < len(_UpperCamelCase						) - 1 and j < len(cells[i]						) - 1:
        neighbour_count += cells[i + 1][j + 1]

      # Rules of the game of life (excerpt from Wikipedia):
      # 1. Any live cell with two or three live neighbours survives.
      # 2. Any dead cell with three live neighbours becomes a live cell.
      # 3. All other live cells die in the next generation.
      #    Similarly, all other dead cells stay dead.
      _lowercase:			List[str]       =     cells[i][j] == 1
      if (
          (alive and 2 <= neighbour_count <= 3)
          or not alive
          and neighbour_count == 3
      ):
        next_generation_row.append(1						)
      else:
        next_generation_row.append(0						)

    next_generation.append(_UpperCamelCase						)
  return next_generation




def  _lowerCAmelCase		(		_UpperCamelCase ,				_UpperCamelCase						):






  """simple docstring"""



  _lowercase:			Optional[int]       =     []
  for _ in range(_UpperCamelCase						):
    # Create output image
    _lowercase:			Tuple       =     Image.new('''RGB''' ,				(len(cells[0]						), len(_UpperCamelCase						))						)
    _lowercase:			str       =     img.load()

    # Save cells to image
    for x in range(len(_UpperCamelCase						)						):
      for y in range(len(cells[0]						)						):
        _lowercase:			str       =     255 - cells[y][x] * 255
        _lowercase:			Tuple       =     (colour, colour, colour)

        # Save image
    images.append(_UpperCamelCase						)
    _lowercase:			List[Any]       =     new_generation(_UpperCamelCase						)
  return images


if __name__ == "__main__":
  A__							=   generate_images(GLIDER, 1_6)
  images[0].save('out.gif', save_all=True, append_images=images[1:])


"""simple docstring"""




from typing import Any

import numpy as np




def  _lowerCAmelCase		(		_UpperCamelCase						):






  """simple docstring"""



  return np.array_equal(_UpperCamelCase ,				matrix.conjugate().T						)




def  _lowerCAmelCase		(		_UpperCamelCase ,				_UpperCamelCase						):






  """simple docstring"""



  _lowercase:			str       =     v.conjugate().T
  _lowercase:			List[Any]       =     v_star.dot(_UpperCamelCase						)
  assert isinstance(_UpperCamelCase ,				np.ndarray						)
  return (v_star_dot.dot(_UpperCamelCase						)) / (v_star.dot(_UpperCamelCase						))




def  _lowerCAmelCase		(		):






  """simple docstring"""



  _lowercase:			int       =     np.array([[2, 2 + 1j, 4], [2 - 1j, 3, 1j], [4, -1j, 1]]						)
  _lowercase:			str       =     np.array([[1], [2], [3]]						)
  assert is_hermitian(_UpperCamelCase						), f'''{a} is not hermitian.'''
  print(rayleigh_quotient(_UpperCamelCase ,				_UpperCamelCase						)						)

  _lowercase:			Any       =     np.array([[1, 2, 4], [2, 3, -1], [4, -1, 1]]						)
  assert is_hermitian(_UpperCamelCase						), f'''{a} is not hermitian.'''
  assert rayleigh_quotient(_UpperCamelCase ,				_UpperCamelCase						) == float(3						)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  tests()
