code: def tf2ss(num, den):
      r"""Transfer function to state-space representation.
  
      Parameters
      ----------
      num, den : array_like
          Sequences representing the coefficients of the numerator and
          denominator polynomials, in order of descending degree. The
          denominator needs to be at least as long as the numerator.
  
      Returns
      -------
      A, B, C, D : ndarray
          State space representation of the system, in controller canonical
          form.
  
      Examples
      --------
      Convert the transfer function:
  
      .. math:: H(s) = \frac{s^2 + 3s + 3}{s^2 + 2s + 1}
  
      >>> num = [1, 3, 3]
      >>> den = [1, 2, 1]
  
      to the state-space representation:
  
      .. math::
  
          \dot{\textbf{x}}(t) =
          \begin{bmatrix} -2 & -1 \\ 1 & 0 \end{bmatrix} \textbf{x}(t) +
          \begin{bmatrix} 1 \\ 0 \end{bmatrix} \textbf{u}(t) \\
  
          \textbf{y}(t) = \begin{bmatrix} 1 & 2 \end{bmatrix} \textbf{x}(t) +
          \begin{bmatrix} 1 \end{bmatrix} \textbf{u}(t)
  
      >>> from scipy.signal import tf2ss
      >>> A, B, C, D = tf2ss(num, den)
      >>> A
      array([[-2., -1.],
             [ 1.,  0.]])
      >>> B
      array([[ 1.],
             [ 0.]])
      >>> C
      array([[ 1.,  2.]])
      >>> D
      array([[ 1.]])
      """
      # Controller canonical state-space representation.
      #  if M+1 = len(num) and K+1 = len(den) then we must have M <= K
      #  states are found by asserting that X(s) = U(s) / D(s)
      #  then Y(s) = N(s) * X(s)
      #
      #   A, B, C, and D follow quite naturally.
      #
      num, den = normalize(num, den)  # Strips zeros, checks arrays
      nn = len(num.shape)
      if nn == 1:
          num = asarray([num], num.dtype)
      M = num.shape[1]
      K = len(den)
      if M > K:
          msg = (
              "Improper transfer function. `num` is longer than `den`."
          )
          raise ValueError(msg)
      if M == 0 or K == 0:  # Null system
          return (
              array([], float),
              array([], float),
              array([], float),
              array([], float),
          )
  
      # pad numerator to have same number of columns has denominator
      num = r_["-1", zeros((num.shape[0], K - M), num.dtype), num]
  
      if num.shape[-1] > 0:
          D = atleast_2d(num[:, 0])
  
      else:
          # We don't assign it an empty array because this system
          # is not 'null'. It just doesn't have a non-zero D
          # matrix. Thus, it should have a non-zero shape so that
          # it can be operated on by functions like 'ss2tf'
          D = array([[0]], float)
  
      if K == 1:
          D = D.reshape(num.shape)
  
          return (
              zeros((1, 1)),
              zeros((1, D.shape[1])),
              zeros((D.shape[0], 1)),
              D,
          )
  
      frow = -array([den[1:]])
      A = r_[frow, eye(K - 2, K - 1)]
      B = eye(K - 1, 1)
      C = num[:, 1:] - outer(num[:, 0], den[1:])
      D = D.reshape((C.shape[0], B.shape[1]))
  
      return A, B, C, D
  
file_path: catboost/contrib/python/scipy/py2/scipy/signal/lti_conversion.py
imports: from __future__ import division, print_function, absolute_import
  import numpy
  import numpy
  from numpy import r_, eye, atleast_2d, poly, dot, asarray, product, zeros, array, outer
  from scipy import linalg
  from .filter_design import tf2zpk, zpk2tf, normalize
label_desc: Use image node_id 1 for calling a global function with example usage: tf2ss(num, den) and returns: A,  B,  C,  D, array,  array,  array,  array, zeros,  zeros,  zeros,  D