The expm() function of scipy.linalg package is used to compute the matrix exponential using Padé approximation. A Padé approximant is the "best" approximation of a function by a rational function of given order. Under this technique, the approximant's power series agrees with the power series of the function it is approximating.
Syntax
scipy.linalg.expm(x)
where x is the input matrix to be exponentiated.
Example 1
Let us consider the following example −
# Import the required libraries from scipy import linalg import numpy as np # Define the input array e = np.array([[100 , 5] , [78 , 36]]) print("Input Array :\n", e) # Calculate the exponential m = linalg.expm(e) # Display the exponential of matrix print("Exponential of e: \n", m)
Output
The above program will generate the following output −
Input Array : [[100 5] [ 78 36]] Exponential of e: [[6.74928440e+45 4.84840154e+44] [7.56350640e+45 5.43330432e+44]]
Example 2
Let us take another example −
# Import the required libraries from scipy import linalg import numpy as np # Define the input array k = np.zeros((3, 3)) print("Input Array :\n", k) # Calculate the exponential n = linalg.expm(k) # Display the exponential of matrix print("Exponential of k: \n", n)
Output
It will generate the following output −
Input Array : [[0. 0. 0.] [0. 0. 0.] [0. 0. 0.]] Exponential of k: [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]]