code: def invresz(r, p, k, tol=1e-3, rtype="avg"):
      """
      Compute b(z) and a(z) from partial fraction expansion.
  
      If `M` is the degree of numerator `b` and `N` the degree of denominator
      `a`::
  
                  b(z)     b[0] + b[1] z**(-1) + ... + b[M] z**(-M)
          H(z) = ------ = ------------------------------------------
                  a(z)     a[0] + a[1] z**(-1) + ... + a[N] z**(-N)
  
      then the partial-fraction expansion H(z) is defined as::
  
                   r[0]                   r[-1]
           = --------------- + ... + ---------------- + k[0] + k[1]z**(-1) ...
             (1-p[0]z**(-1))         (1-p[-1]z**(-1))
  
      If there are any repeated roots (closer than `tol`), then the partial
      fraction expansion has terms like::
  
               r[i]              r[i+1]                    r[i+n-1]
          -------------- + ------------------ + ... + ------------------
          (1-p[i]z**(-1))  (1-p[i]z**(-1))**2         (1-p[i]z**(-1))**n
  
      This function is used for polynomials in negative powers of z,
      such as digital filters in DSP.  For positive powers, use `invres`.
  
      Parameters
      ----------
      r : array_like
          Residues.
      p : array_like
          Poles.
      k : array_like
          Coefficients of the direct polynomial term.
      tol : float, optional
          The tolerance for two roots to be considered equal. Default is 1e-3.
      rtype : {'max', 'min, 'avg'}, optional
          How to determine the returned root if multiple roots are within
          `tol` of each other.
  
            - 'max': pick the maximum of those roots.
            - 'min': pick the minimum of those roots.
            - 'avg': take the average of those roots.
  
      Returns
      -------
      b : ndarray
          Numerator polynomial coefficients.
      a : ndarray
          Denominator polynomial coefficients.
  
      See Also
      --------
      residuez, unique_roots, invres
  
      """
      extra = asarray(k)
      p, indx = cmplx_sort(p)
      r = take(r, indx, 0)
      pout, mult = unique_roots(p, tol=tol, rtype=rtype)
      p = []
      for k in range(len(pout)):
          p.extend([pout[k]] * mult[k])
      a = atleast_1d(poly(p))
      if len(extra) > 0:
          b = polymul(extra, a)
      else:
          b = [0]
      indx = 0
      brev = asarray(b)[::-1]
      for k in range(len(pout)):
          temp = []
          # Construct polynomial which does not include any of this root
          for l in range(len(pout)):
              if l != k:
                  temp.extend([pout[l]] * mult[l])
          for m in range(mult[k]):
              t2 = temp[:]
              t2.extend([pout[k]] * (mult[k] - m - 1))
              brev = polyadd(
                  brev, (r[indx] * atleast_1d(poly(t2)))[::-1]
              )
              indx += 1
      b = real_if_close(brev[::-1])
      return b, a
  
imports: from __future__ import division, print_function, absolute_import
  import operator
  import threading
  import sys
  import timeit
  from scipy.spatial import cKDTree
  from .None import sigtools, dlti
  from ._upfirdn import upfirdn, _output_len
  from scipy._lib.six import callable
  from scipy._lib._version import NumpyVersion
  from scipy import fftpack, linalg
  from scipy.fftpack.helper import _init_nd_shape_and_axes_sorted
  from numpy import allclose, angle, arange, argsort, array, asarray, atleast_1d, atleast_2d, cast, dot, exp, expand_dims, iscomplexobj, mean, ndarray, newaxis, ones, pi, poly, polyadd, polyder, polydiv, polymul, polysub, polyval, product, r_, ravel, real_if_close, reshape, roots, sort, take, transpose, unique, where, zeros, zeros_like
  import numpy
  import math
  from scipy.special import factorial
  from .windows import get_window
  from ._arraytools import axis_slice, axis_reverse, odd_ext, even_ext, const_ext
  from .filter_design import cheby1, _validate_sos
  from .fir_filter_design import firwin
label_desc: Use image node_id 31 for calling a global function with example usage: invresz(r, p, k, tol, rtype) and returns: b,  a