如何使用 SciPy 找到方阵的特征值和特征向量?

我们可以在以下关系的帮助下找到方阵 A 的特征值和特征向量 -

SciPy 库有scipy. linalg.eig()用于计算方阵的特征值和特征向量的函数。

让我们了解如何使用此函数来计算矩阵的逆 -

示例

2 × 2 矩阵的特征值和特征向量

#Importing the scipy package
import scipy

#Importing the numpy package
import numpy as np

#Declaring the numpy array(Square Matrix)
A = np.array([[3,3.5],[3.2,3.6]])

#Passing the values to scipy.linalg.eig() function
eigvalues, eigvectors = scipy.linalg.eig(A)

#Printing the result for eigenvalues
print(eigvalues)

#Printing the result for eigenvectors
print(eigvectors)
输出结果
[-0.06005952+0.j 6.66005952+0.j]
[[-0.75283678 -0.6911271 ]
[ 0.65820725 -0.72273324]]

示例

3 x 3 矩阵的特征值和特征向量

import scipy
import numpy as np
A = np.array([[2,1,-2],[1,0,0],[0,1,0]])
eigvalues, eigvectors = scipy.linalg.eig(A)
print(eigvalues)
print(eigvectors)
输出结果
[-1.+0.j 2.+0.j 1.+0.j]
[[-0.57735027 -0.87287156 0.57735027]
[ 0.57735027 -0.43643578 0.57735027]
[-0.57735027 -0.21821789 0.57735027]]