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)
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP