parameters: (A, disp=True)
docstring: Matrix sign function.
  
      Extension of the scalar sign(x) to matrices.
  
      Parameters
      ----------
      A : (N, N) array_like
          Matrix at which to evaluate the sign function
      disp : bool, optional
          Print warning if error in the result is estimated large
          instead of returning estimated error. (Default: True)
  
      Returns
      -------
      signm : (N, N) ndarray
          Value of the sign function at `A`
      errest : float
          (if disp == False)
  
          1-norm of the estimated error, ||err||_1 / ||A||_1
  
      Examples
      --------
      >>> from scipy.linalg import signm, eigvals
      >>> a = [[1,2,3], [1,2,1], [1,1,1]]
      >>> eigvals(a)
      array([ 4.12488542+0.j, -0.76155718+0.j,  0.63667176+0.j])
      >>> eigvals(signm(a))
      array([-1.+0.j,  1.+0.j,  1.+0.j])
docstring_summary: Matrix sign function.
docstring_tokens: Matrix sign function .
function: def signm(A, disp=True):
      """
      Matrix sign function.
  
      Extension of the scalar sign(x) to matrices.
  
      Parameters
      ----------
      A : (N, N) array_like
          Matrix at which to evaluate the sign function
      disp : bool, optional
          Print warning if error in the result is estimated large
          instead of returning estimated error. (Default: True)
  
      Returns
      -------
      signm : (N, N) ndarray
          Value of the sign function at `A`
      errest : float
          (if disp == False)
  
          1-norm of the estimated error, ||err||_1 / ||A||_1
  
      Examples
      --------
      >>> from scipy.linalg import signm, eigvals
      >>> a = [[1,2,3], [1,2,1], [1,1,1]]
      >>> eigvals(a)
      array([ 4.12488542+0.j, -0.76155718+0.j,  0.63667176+0.j])
      >>> eigvals(signm(a))
      array([-1.+0.j,  1.+0.j,  1.+0.j])
  
      """
      A = _asarray_square(A)
  
      def rounded_sign(x):
          rx = np.real(x)
          if rx.dtype.char == 'f':
              c = 1e3*feps*amax(x)
          else:
              c = 1e3*eps*amax(x)
          return sign((absolute(rx) > c) * rx)
      result, errest = funm(A, rounded_sign, disp=0)
      errtol = {0:1e3*feps, 1:1e3*eps}[_array_precision[result.dtype.char]]
      if errest < errtol:
          return result
  
      # Handle signm of defective matrices:
  
      # See "E.D.Denman and J.Leyva-Ramos, Appl.Math.Comp.,
      # 8:237-250,1981" for how to improve the following (currently a
      # rather naive) iteration process:
  
      # a = result # sometimes iteration converges faster but where??
  
      # Shifting to avoid zero eigenvalues. How to ensure that shifting does
      # not change the spectrum too much?
      vals = svd(A, compute_uv=0)
      max_sv = np.amax(vals)
      # min_nonzero_sv = vals[(vals>max_sv*errtol).tolist().count(1)-1]
      # c = 0.5/min_nonzero_sv
      c = 0.5/max_sv
      S0 = A + c*np.identity(A.shape[0])
      prev_errest = errest
      for i in range(100):
          iS0 = inv(S0)
          S0 = 0.5*(S0 + iS0)
          Pp = 0.5*(dot(S0,S0)+S0)
          errest = norm(dot(Pp,Pp)-Pp,1)
          if errest < errtol or prev_errest == errest:
              break
          prev_errest = errest
      if disp:
          if not isfinite(errest) or errest >= errtol:
              print("signm result may be inaccurate, approximate err =", errest)
          return S0
      else:
          return S0, errest
function_tokens: def signm ( A , disp = True ) : A = _asarray_square ( A ) def rounded_sign ( x ) : rx = np . real ( x ) if rx . dtype . char == 'f' : c = 1e3 * feps * amax ( x ) else : c = 1e3 * eps * amax ( x ) return sign ( ( absolute ( rx ) > c ) * rx ) result , errest = funm ( A , rounded_sign , disp = 0 ) errtol = { 0 : 1e3 * feps , 1 : 1e3 * eps } [ _array_precision [ result . dtype . char ] ] if errest < errtol : return result # Handle signm of defective matrices: # See "E.D.Denman and J.Leyva-Ramos, Appl.Math.Comp., # 8:237-250,1981" for how to improve the following (currently a # rather naive) iteration process: # a = result # sometimes iteration converges faster but where?? # Shifting to avoid zero eigenvalues. How to ensure that shifting does # not change the spectrum too much? vals = svd ( A , compute_uv = 0 ) max_sv = np . amax ( vals ) # min_nonzero_sv = vals[(vals>max_sv*errtol).tolist().count(1)-1] # c = 0.5/min_nonzero_sv c = 0.5 / max_sv S0 = A + c * np . identity ( A . shape [ 0 ] ) prev_errest = errest for i in range ( 100 ) : iS0 = inv ( S0 ) S0 = 0.5 * ( S0 + iS0 ) Pp = 0.5 * ( dot ( S0 , S0 ) + S0 ) errest = norm ( dot ( Pp , Pp ) - Pp , 1 ) if errest < errtol or prev_errest == errest : break prev_errest = errest if disp : if not isfinite ( errest ) or errest >= errtol : print ( "signm result may be inaccurate, approximate err =" , errest ) return S0 else : return S0 , errest