code: def lfilter_zi(b, a):
      """
      Construct initial conditions for lfilter for step response steady-state.
  
      Compute an initial state `zi` for the `lfilter` function that corresponds
      to the steady state of the step response.
  
      A typical use of this function is to set the initial state so that the
      output of the filter starts at the same value as the first element of
      the signal to be filtered.
  
      Parameters
      ----------
      b, a : array_like (1-D)
          The IIR filter coefficients. See `lfilter` for more
          information.
  
      Returns
      -------
      zi : 1-D ndarray
          The initial state for the filter.
  
      See Also
      --------
      lfilter, lfiltic, filtfilt
  
      Notes
      -----
      A linear filter with order m has a state space representation (A, B, C, D),
      for which the output y of the filter can be expressed as::
  
          z(n+1) = A*z(n) + B*x(n)
          y(n)   = C*z(n) + D*x(n)
  
      where z(n) is a vector of length m, A has shape (m, m), B has shape
      (m, 1), C has shape (1, m) and D has shape (1, 1) (assuming x(n) is
      a scalar).  lfilter_zi solves::
  
          zi = A*zi + B
  
      In other words, it finds the initial condition for which the response
      to an input of all ones is a constant.
  
      Given the filter coefficients `a` and `b`, the state space matrices
      for the transposed direct form II implementation of the linear filter,
      which is the implementation used by scipy.signal.lfilter, are::
  
          A = scipy.linalg.companion(a).T
          B = b[1:] - a[1:]*b[0]
  
      assuming `a[0]` is 1.0; if `a[0]` is not 1, `a` and `b` are first
      divided by a[0].
  
      Examples
      --------
      The following code creates a lowpass Butterworth filter. Then it
      applies that filter to an array whose values are all 1.0; the
      output is also all 1.0, as expected for a lowpass filter.  If the
      `zi` argument of `lfilter` had not been given, the output would have
      shown the transient signal.
  
      >>> from numpy import array, ones
      >>> from scipy.signal import lfilter, lfilter_zi, butter
      >>> b, a = butter(5, 0.25)
      >>> zi = lfilter_zi(b, a)
      >>> y, zo = lfilter(b, a, ones(10), zi=zi)
      >>> y
      array([1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])
  
      Another example:
  
      >>> x = array([0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0])
      >>> y, zf = lfilter(b, a, x, zi=zi*x[0])
      >>> y
      array([ 0.5       ,  0.5       ,  0.5       ,  0.49836039,  0.48610528,
          0.44399389,  0.35505241])
  
      Note that the `zi` argument to `lfilter` was computed using
      `lfilter_zi` and scaled by `x[0]`.  Then the output `y` has no
      transient until the input drops from 0.5 to 0.0.
  
      """
  
      # FIXME: Can this function be replaced with an appropriate
      # use of lfiltic?  For example, when b,a = butter(N,Wn),
      #    lfiltic(b, a, y=numpy.ones_like(a), x=numpy.ones_like(b)).
      #
  
      # We could use scipy.signal.normalize, but it uses warnings in
      # cases where a ValueError is more appropriate, and it allows
      # b to be 2D.
      b = np.atleast_1d(b)
      if b.ndim != 1:
          raise ValueError("Numerator b must be 1-D.")
      a = np.atleast_1d(a)
      if a.ndim != 1:
          raise ValueError("Denominator a must be 1-D.")
  
      while len(a) > 1 and a[0] == 0.0:
          a = a[1:]
      if a.size < 1:
          raise ValueError(
              "There must be at least one nonzero `a` coefficient."
          )
  
      if a[0] != 1.0:
          # Normalize the coefficients so a[0] == 1.
          b = b / a[0]
          a = a / a[0]
  
      n = max(len(a), len(b))
  
      # Pad a or b with zeros so they are the same length.
      if len(a) < n:
          a = np.r_[a, np.zeros(n - len(a))]
      elif len(b) < n:
          b = np.r_[b, np.zeros(n - len(b))]
  
      IminusA = (
          np.eye(n - 1, dtype=np.result_type(a, b))
          - linalg.companion(a).T
      )
      B = b[1:] - a[1:] * b[0]
      # Solve zi = A*zi + B
      zi = np.linalg.solve(IminusA, B)
  
      # For future reference: we could also use the following
      # explicit formulas to solve the linear system:
      #
      # zi = np.zeros(n - 1)
      # zi[0] = B.sum() / IminusA[:,0].sum()
      # asum = 1.0
      # csum = 0.0
      # for k in range(1,n-1):
      #     asum += a[k]
      #     csum += b[k] - a[k]*b[0]
      #     zi[k] = asum*zi[0] - csum
  
      return zi
  
imports: import operator
  import math
  import timeit
  from scipy.spatial import cKDTree
  from .None import sigtools, dlti
  from ._upfirdn import upfirdn, _output_len, _upfirdn_modes
  from scipy import linalg, fft
  from scipy.fft._helper import _init_nd_shape_and_axes
  from scipy._lib._util import prod
  import numpy
  from scipy.special import lambertw
  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
  from ._sosfilt import _sosfilt
  import warnings
label_desc: Use image node_id 45 for calling a global function with example usage: lfilter_zi(b, a) and returns: zi