Computer >> Máy Tính >  >> Lập trình >> Python

Python - scipy.linalg.expm

expm () chức năng của scipy.linalg gói được sử dụng để tính toán ma trận theo cấp số nhân bằng cách sử dụng xấp xỉ Padé. Một xấp xỉ Padé là xấp xỉ "tốt nhất" của một hàm theo một hàm hữu tỉ có bậc đã cho. Theo kỹ thuật này, chuỗi lũy thừa của hàm gần đúng đồng ý với chuỗi lũy thừa của hàm mà nó đang tính gần đúng.

Cú pháp

scipy.linalg.expm(x)

trong đó x là ma trận đầu vào được tính lũy thừa.

Ví dụ 1

Chúng ta hãy xem xét ví dụ sau -

# 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)

Đầu ra

Chương trình trên sẽ tạo ra kết quả sau -

Input Array :
 [[100 5]
 [ 78 36]]
Exponential of e:
 [[6.74928440e+45 4.84840154e+44]
 [7.56350640e+45 5.43330432e+44]]

Ví dụ 2

Hãy để chúng tôi lấy một ví dụ khác -

# 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)

Đầu ra

Nó sẽ tạo ra kết quả sau -

Input Array :
 [[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]
Exponential of k:
 [[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]