bundles / scipy 1.17.1 / scipy / linalg / _matfuncs / sqrtm
function
scipy.linalg._matfuncs:sqrtm
source: /scipy/linalg/_matfuncs.py :415
Signature
def sqrtm ( A , disp = <object object at 0x0000> , blocksize = <object object at 0x0000> ) Summary
Compute, if exists, the matrix square root.
Extended Summary
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.
Array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details.
Parameters
A: ndarrayInput with last two dimensions are square
(..., n, n).disp: bool, optionalPrint warning if error in the result is estimated large instead of returning estimated error. (Default: True)
blocksize: integer, optional
Returns
sqrtm: ndarrayComputed matrix squareroot of
Awith same size(..., n, n).errest: floatFrobenius norm of the estimated error, ||err||_F / ||A||_F. Only returned, if
dispis set toFalse. This return argument will be removed in version 1.20.0 and only the sqrtm result will be returned.
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.
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 r.dot(r)✗
Aliases
-
scipy.linalg.sqrtm