code: def cond(A):
      
      if A.shape[0] != A.shape[1]:
          raise ValueError('expected square matrix')
  
      if sparse.isspmatrix(A):
          A = A.todense()
  
      # 2-Norm Condition Number
      from scipy.linalg import svd
  
      U, Sigma, Vh = svd(A)
      return np.max(Sigma)/min(Sigma)
docs: Return condition number of A.
  
      Parameters
      ----------
      A   : {dense or sparse matrix}
          e.g. array, matrix, csr_matrix, ...
  
      Returns
      -------
      2-norm condition number through use of the SVD
      Use for small to moderate sized dense matrices.
      For large sparse matrices, use condest.
  
      Notes
      -----
      The condition number measures how large of a change in
      the problems solution is caused by a change in problem's input.
      Large condition numbers indicate that small perturbations
      and numerical errors are magnified greatly when solving the system.
  
      Examples
      --------
      >>> import numpy as np
      >>> from pyamg.util.linalg import condest
      >>> c = condest(np.array([[1.0,0.],[0.,2.0]]))
      >>> print c
      2.0