The cosm() function of scipy.linalg package is used to compute the cosine of an input matrix. This routine uses expm to compute the matrix exponentials.
Syntax
scipy.linalg.cosm(x)
where x is the input array.
Example 1
Let us consider the following example −
# 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)Output
The above program will generate the following output −
Array Input : [[121 10] [ 77 36]] Cosine of Q: [[-0.89675008 -0.00369979] [-0.02848841 -0.86530184]]
Example 2
Let us take another example −
# 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)Output
The above program will generate the following output −
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]]