Python – scipy.linalg.cosm


scipy.linalg 包的 cosm() 函式用於計算輸入矩陣的餘弦。此例程使用 expm 來計算矩陣的指數。

語法

scipy.linalg.cosm(x)

其中 x 是輸入陣列。

示例 1

考慮以下示例 -

# Import the required libraries
from scipy import linalg
import numpy as np

# Define the input array
q = np.array([[121 , 10] , [77 , 36]])
print("Array Input :\n", q)

# Calculate the Cosine
r = linalg.cosm(q)

# Display the Cosine of matrix
print("Cosine of Q: \n", r)

輸出

以上程式將生成以下輸出 -

Array Input :
 [[121 10]
 [ 77 36]]
Cosine of Q:
 [[-0.89675008 -0.00369979]
 [-0.02848841 -0.86530184]]

示例 2

再舉個例子 -

# Import the required libraries
from scipy import linalg
import numpy as np

# Define the input array
x = np.ones((3, 3))
print("Array Input :\n", x)

# Calculate the Cosine
a = linalg.cosm(x)

# Display the Cosine of matrix
print("Cosine of X: \n", a)

輸出

以上程式將生成以下輸出 -

Array Input :
 [[1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]]
Cosine of X:
 [[ 0.33666917 -0.66333083 -0.66333083]
 [-0.66333083 0.33666917 -0.66333083]
 [-0.66333083 -0.66333083 0.33666917]]

更新於: 2021-12-24

170 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告