Skip to main content
`Ctrl`+`K`
scipy.linalg.

# sqrtm

scipy.linalg.sqrtm(A, disp=<object object>, blocksize=<object object>)

  Compute, if exists, the matrix square root.

  The matrix square root of `A` is a matrix `X` such that `X @ X = A`. Every square matrix is not guaranteed to have a matrix square root, for example, the array `[[0, 1], [0, 0]]` does not have a square root.

  Moreover, not every real matrix has a real square root. Hence, for real-valued matrices the return type can be complex if, numerically, there is an eigenvalue on the negative real axis.

  Parameters:
    Andarray

      Input with last two dimensions are square `(..., n, n)`.

    dispbool, optional

      Print warning if error in the result is estimated large instead of returning estimated error. (Default: True)

      Deprecated since version 1.16.0: The disp argument is deprecated and will be removed in SciPy 1.18.0. The previously returned error estimate can be computed as `norm(X @ X - A, 'fro')**2 / norm(A, 'fro')`

    blocksizeinteger, optional

      Deprecated since version 1.16.0: The blocksize argument is deprecated as it is unused by the algorithm and will be removed in SciPy 1.18.0.

  Returns:
    sqrtmndarray

      Computed matrix squareroot of A with same size `(..., n, n)`.

    errestfloat

      Frobenius norm of the estimated error, ||err||_F / ||A||_F. Only returned, if `disp` is set to `False`. This return argument will be removed in version 1.20.0 and only the sqrtm result will be returned.

      Deprecated since version 1.16.0.

  Notes

  This function uses the Schur decomposition method to compute the matrix square root following [1] and for real matrices [2]. Moreover, note that, there exist matrices that have square roots that are not polynomials in `A`. For a classical example from [2], the matrix satisfies:

      [ a, a**2 + 1]**2     [-1,  0]
      [-1,       -a]     =  [ 0, -1]

  for any scalar `a` but it is not a polynomial in `-I`. Thus, they will not be found by this function.

  References

  [1]

  Edvin Deadman, Nicholas J. Higham, Rui Ralha (2013) “Blocked Schur Algorithms for Computing the Matrix Square Root, Lecture Notes in Computer Science, 7782. pp. 171-182. DOI:10.1016/0024-3795(87)90118-2

  [2] (1,2)

  Nicholas J. Higham (1987) “Computing real square roots of a real matrix”, Linear Algebra and its Applications, 88/89:405-430. DOI:10.1016/0024-3795(87)90118-2

  Examples

      >>> import numpy as np
      >>> from scipy.linalg import sqrtm
      >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
      >>> r = sqrtm(a)
      >>> r
      array([[ 0.75592895,  1.13389342],
             [ 0.37796447,  1.88982237]])
      >>> r.dot(r)
      array([[ 1.,  3.],
             [ 1.,  4.]])