code: def sosfilt(sos, x, axis=-1, zi=None):
      """
      Filter data along one dimension using cascaded second-order sections.
  
      Filter a data sequence, `x`, using a digital IIR filter defined by
      `sos`.
  
      Parameters
      ----------
      sos : array_like
          Array of second-order filter coefficients, must have shape
          ``(n_sections, 6)``. Each row corresponds to a second-order
          section, with the first three columns providing the numerator
          coefficients and the last three providing the denominator
          coefficients.
      x : array_like
          An N-dimensional input array.
      axis : int, optional
          The axis of the input data array along which to apply the
          linear filter. The filter is applied to each subarray along
          this axis.  Default is -1.
      zi : array_like, optional
          Initial conditions for the cascaded filter delays.  It is a (at
          least 2D) vector of shape ``(n_sections, ..., 2, ...)``, where
          ``..., 2, ...`` denotes the shape of `x`, but with ``x.shape[axis]``
          replaced by 2.  If `zi` is None or is not given then initial rest
          (i.e. all zeros) is assumed.
          Note that these initial conditions are *not* the same as the initial
          conditions given by `lfiltic` or `lfilter_zi`.
  
      Returns
      -------
      y : ndarray
          The output of the digital filter.
      zf : ndarray, optional
          If `zi` is None, this is not returned, otherwise, `zf` holds the
          final filter delay values.
  
      See Also
      --------
      zpk2sos, sos2zpk, sosfilt_zi, sosfiltfilt, sosfreqz
  
      Notes
      -----
      The filter function is implemented as a series of second-order filters
      with direct-form II transposed structure. It is designed to minimize
      numerical precision errors for high-order filters.
  
      .. versionadded:: 0.16.0
  
      Examples
      --------
      Plot a 13th-order filter's impulse response using both `lfilter` and
      `sosfilt`, showing the instability that results from trying to do a
      13th-order filter in a single stage (the numerical error pushes some poles
      outside of the unit circle):
  
      >>> import matplotlib.pyplot as plt
      >>> from scipy import signal
      >>> b, a = signal.ellip(13, 0.009, 80, 0.05, output='ba')
      >>> sos = signal.ellip(13, 0.009, 80, 0.05, output='sos')
      >>> x = signal.unit_impulse(700)
      >>> y_tf = signal.lfilter(b, a, x)
      >>> y_sos = signal.sosfilt(sos, x)
      >>> plt.plot(y_tf, 'r', label='TF')
      >>> plt.plot(y_sos, 'k', label='SOS')
      >>> plt.legend(loc='best')
      >>> plt.show()
  
      """
      x = _validate_x(x)
      sos, n_sections = _validate_sos(sos)
      x_zi_shape = list(x.shape)
      x_zi_shape[axis] = 2
      x_zi_shape = tuple([n_sections] + x_zi_shape)
      inputs = [sos, x]
      if zi is not None:
          inputs.append(np.asarray(zi))
      dtype = np.result_type(*inputs)
      if dtype.char not in "fdgFDGO":
          raise NotImplementedError(
              "input type '%s' not supported" % dtype
          )
      if zi is not None:
          zi = np.array(
              zi, dtype
          )  # make a copy so that we can operate in place
          if zi.shape != x_zi_shape:
              raise ValueError(
                  "Invalid zi shape. With axis=%r, an input with "
                  "shape %r, and an sos array with %d sections, zi "
                  "must have shape %r, got %r."
                  % (axis, x.shape, n_sections, x_zi_shape, zi.shape)
              )
          return_zi = True
      else:
          zi = np.zeros(x_zi_shape, dtype=dtype)
          return_zi = False
      axis = axis % x.ndim  # make positive
      x = np.moveaxis(x, axis, -1)
      zi = np.moveaxis(zi, [0, axis + 1], [-2, -1])
      x_shape, zi_shape = x.shape, zi.shape
      x = np.reshape(x, (-1, x.shape[-1]))
      x = np.array(
          x, dtype, order="C"
      )  # make a copy, can modify in place
      zi = np.ascontiguousarray(np.reshape(zi, (-1, n_sections, 2)))
      sos = sos.astype(dtype, copy=False)
      _sosfilt(sos, x, zi)
      x.shape = x_shape
      x = np.moveaxis(x, -1, axis)
      if return_zi:
          zi.shape = zi_shape
          zi = np.moveaxis(zi, [-2, -1], [0, axis + 1])
          out = (x, zi)
      else:
          out = x
      return out
  
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 51 for calling a global function with example usage: sosfilt(sos, x, axis, zi) and returns: out