Python – scipy.linalg.sqrtm


scipy.linalg 包的 sqrtm() 函数可以用来查找输入矩阵的平方根。

语法

scipy.linalg.sqrtm(x)

示例 1

考虑以下示例 −

Open Compiler
# Importing the required libraries from scipy from scipy import linalg import numpy as np # Define the input array x = np.array([[14 , 2] , [89 , 33]]) print("Input array:", x) # Calculate the square root r = linalg.sqrtm(x) # Display the square root print("Square Root of x: ", r)

Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.

输出

它将生成以下输出 −

Input array:
[[14 2]
[89 33]]
Square Root of x:
[[3.43430132 0.22262855]
[9.90697038 5.54927253]]

示例 2

我们以另一个示例为例 −

Open Compiler
# Importing the required libraries from scipy from scipy import linalg import numpy as np # Define the input array x = np.array([[25 , 8] , [66 , 54]]) print("Input array:", x) # Calculate the square root m = linalg.sqrtm(x, disp=False) # Display the square root print("Square Root of x: ", m)

输出

以上程序将生成以下输出 −

Input array:
[[25 8]
[66 54]]
Square Root of x:
(array([[4.59645076, 0.68513573],
[5.65236974, 7.08006776]]), 4.668211715240082e-30)

更新于: 2021 年 12 月 22 日

866 次浏览

启动您的 职业

完成课程,获得认证

开始
广告