code: def calc_Z(A, x):
      
      if (type(x) is pd.DataFrame) or (type(x) is pd.Series):
          x = x.values
      x = x.reshape((1, -1))   # use numpy broadcasting - much faster
      # (but has to ensure that x is a row vector)
      # old mathematical form:
      # return A.dot(np.diagflat(x))
      if type(A) is pd.DataFrame:
          return pd.DataFrame(A.values * x, index=A.index, columns=A.columns)
      else:
          return A*x
docs: calculate the Z matrix (flows) from A and x
  
      Parameters
      ----------
      A : pandas.DataFrame or numpy.array
          Symmetric input output table (coefficients)
      x : pandas.DataFrame or numpy.array
          Industry output column vector
  
      Returns
      -------
      pandas.DataFrame or numpy.array
          Symmetric input output table (flows) Z
          The type is determined by the type of A.
          If DataFrame index/columns as A