code: def py_multiplicative_inverse(a, n):
      """Multiplicative inverse of a modulo n (in Python).
      Implements extended Euclidean algorithm.
      Args:
          a: int-like np.ndarray.
          n: int.
      Returns:
          Multiplicative inverse as an int32 np.ndarray with same shape as a.
      """
      batched_a = np.asarray(a, dtype=np.int32)
      n = np.asarray(n, dtype=np.int32)
      batched_inverse = []
      for a in np.nditer(batched_a):
          inverse = 0
          new_inverse = 1
          remainder = n
          new_remainder = a
          while new_remainder != 0:
              quotient = remainder // new_remainder
              (inverse, new_inverse) = (
                  new_inverse,
                  inverse - quotient * new_inverse,
              )
              (remainder, new_remainder) = (
                  new_remainder,
                  remainder - quotient * new_remainder,
              )
  
          if remainder > 1:
              raise ValueError(
                  "Inverse for {} modulo {} does not exist.".format(
                      a, n
                  )
              )
          if inverse < 0:
              inverse += n
          batched_inverse.append(inverse)
      return np.asarray(batched_inverse, dtype=np.int32).reshape(
          batched_a.shape
      )
  
file_path: DIG/dig/ggraph/method/GraphDF/model/df_utils.py
imports: import sys
  import warnings
  import torch
  import torch.nn.functional
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: py_multiplicative_inverse(a, n) and returns: np