code: def calc_A(Z, x):
      
      if (type(x) is pd.DataFrame) or (type(x) is pd.Series):
          x = x.values
      if (type(x) is not np.ndarray) and (x == 0):
          recix = 0
      else:
          with warnings.catch_warnings():
              # catch the divide by zero warning
              # we deal wit that by setting to 0 afterwards
              warnings.simplefilter('ignore')
              recix = 1/x
          recix[recix == np.inf] = 0
          recix = recix.reshape((1, -1))
      # use numpy broadcasting - factor ten faster
      # Mathematical form - slow
      # return Z.dot(np.diagflat(recix))
      if type(Z) is pd.DataFrame:
          return pd.DataFrame(Z.values * recix, index=Z.index, columns=Z.columns)
      else:
          return Z*recix
docs: Calculate the A matrix (coefficients) from Z and x
  
      Parameters
      ----------
      Z : pandas.DataFrame or numpy.array
          Symmetric input output table (flows)
      x : pandas.DataFrame or numpy.array
          Industry output column vector
  
      Returns
      -------
      pandas.DataFrame or numpy.array
          Symmetric input output table (coefficients) A
          The type is determined by the type of Z.
          If DataFrame index/columns as Z