code: def cmplx_sort(p):
      """Sort roots based on magnitude.
  
      Parameters
      ----------
      p : array_like
          The roots to sort, as a 1-D array.
  
      Returns
      -------
      p_sorted : ndarray
          Sorted roots.
      indx : ndarray
          Array of indices needed to sort the input `p`.
  
      Examples
      --------
      >>> from scipy import signal
      >>> vals = [1, 4, 1+1.j, 3]
      >>> p_sorted, indx = signal.cmplx_sort(vals)
      >>> p_sorted
      array([1.+0.j, 1.+1.j, 3.+0.j, 4.+0.j])
      >>> indx
      array([0, 2, 3, 1])
      """
      p = np.asarray(p)
      indx = np.argsort(abs(p))
      return np.take(p, indx, 0), indx
  
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 32 for calling a global function with example usage: cmplx_sort(p) and returns: np,  indx