Python – scipy.linalg.sqrtm
scipy.linalg 包的 sqrtm() 函数可以用来查找输入矩阵的平方根。
语法
scipy.linalg.sqrtm(x)
示例 1
考虑以下示例 −
# 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)
输出
它将生成以下输出 −
Input array: [[14 2] [89 33]] Square Root of x: [[3.43430132 0.22262855] [9.90697038 5.54927253]]
示例 2
我们以另一个示例为例 −
# 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)
广告