最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

numpy求矩陣的特征值與特征向量(np.linalg.eig函數(shù)用法)

 更新時間:2023年02月05日 08:58:37   作者:Codefmeister  
這篇文章主要介紹了numpy求矩陣的特征值與特征向量(np.linalg.eig函數(shù)用法),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

求矩陣的特征值與特征向量(np.linalg.eig)

語法

np.linalg.eig(a)

功能

Compute the eigenvalues and right eigenvectors of a square array.

求方陣(n x n)的特征值與右特征向量

Parameters

a : (…, M, M) array

Matrices for which the eigenvalues and right eigenvectors will be computed

a是一個矩陣Matrix的數(shù)組。每個矩陣M都會被計算其特征值與特征向量。

Returns

w : (…, M) array

The eigenvalues, each repeated according to its multiplicity.
The eigenvalues are not necessarily ordered. The resulting array will be of complex type, unless the imaginary part is zero in which case it will be cast to a real type. When a is real the resulting eigenvalues will be real (0 imaginary part) or occur in conjugate pairs

返回的w是其特征值。特征值不會特意進行排序。返回的array一般都是復數(shù)形式,除非虛部為0,會被cast為實數(shù)。當a是實數(shù)類型時,返回的就是實數(shù)。

v : (…, M, M) array

The normalized (unit “length”) eigenvectors, such that the column v[:,i] is the eigenvector corresponding to the eigenvalue w[i].

返回的v是歸一化后的特征向量(length為1)。特征向量v[:,i]對應特征值w[i]。

Raises

LinAlgError

If the eigenvalue computation does not converge.

Ralated Function:

See Also

eigvals : eigenvalues of a non-symmetric array.
eigh : eigenvalues and eigenvectors of a real symmetric or complex Hermitian (conjugate symmetric) array.
eigvalsh : eigenvalues of a real symmetric or complex Hermitian (conjugate symmetric) array.
scipy.linalg.eig : Similar function in SciPy that also solves the generalized eigenvalue problem.
scipy.linalg.schur : Best choice for unitary and other non-Hermitian normal matrices.

相關(guān)的函數(shù)有:

  • eigvals:計算非對稱矩陣的特征值
  • eigh:實對稱矩陣或者復共軛對稱矩陣(Hermitian)的特征值與特征向量
  • eigvalsh: 實對稱矩陣或者復共軛對稱矩陣(Hermitian)的特征值與特征向量
  • scipy.linalg.eig
  • scipy.linalg.schur

Notes

… versionadded:: 1.8.0

Broadcasting rules apply, see the numpy.linalg documentation for details.

This is implemented using the _geev LAPACK routines which compute the eigenvalues and eigenvectors of general square arrays.

The number w is an eigenvalue of a if there exists a vector v such that a @ v = w * v. Thus, the arrays a, w, and v satisfy the equations a @ v[:,i] = w[i] * v[:,i] for :math:i \\in \\{0,...,M-1\\}.

The array v of eigenvectors may not be of maximum rank, that is, some of the columns may be linearly dependent, although round-off error may obscure that fact. If the eigenvalues are all different, then theoretically the eigenvectors are linearly independent and a can be diagonalized by a similarity transformation using v, i.e, inv(v) @ a @ v is diagonal.

For non-Hermitian normal matrices the SciPy function scipy.linalg.schur is preferred because the matrix v is guaranteed to be unitary, which is not the case when using eig. The Schur factorization produces an upper triangular matrix rather than a diagonal matrix, but for normal matrices only the diagonal of the upper triangular matrix is needed, the rest is roundoff error.

Finally, it is emphasized that v consists of the right (as in right-hand side) eigenvectors of a. A vector y satisfying y.T @ a = z * y.T for some number z is called a left eigenvector of a, and, in general, the left and right eigenvectors of a matrix are not necessarily the (perhaps conjugate) transposes of each other.

References

G. Strang, Linear Algebra and Its Applications, 2nd Ed., Orlando, FL,
Academic Press, Inc., 1980, Various pp.

需要說明的是,特征向量之間可能存在線性相關(guān)關(guān)系,即返回的v可能不是滿秩的。但如果特征值都不同的話,理論上來說,所有特征向量都是線性無關(guān)的。

此時可以利用inv(v)@ a @ v來計算特征值的對角矩陣(對角線上的元素是特征值,其余元素為0),同時可以用v @ diag(w) @ inv(v)來恢復a。
同時需要說明的是,這里得到的特征向量都是右特征向量。

即 Ax=λx

Examples

>>> from numpy import linalg as LA

(Almost) trivial example with real e-values and e-vectors.

>>> w, v = LA.eig(np.diag((1, 2, 3)))
>>> w; v
array([1., 2., 3.])
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])

Real matrix possessing complex e-values and e-vectors; note that the
e-values are complex conjugates of each other.

>>> w, v = LA.eig(np.array([[1, -1], [1, 1]]))
>>> w; v
array([1.+1.j, 1.-1.j])
array([[0.70710678+0.j        , 0.70710678-0.j        ],
       [0.        -0.70710678j, 0.        +0.70710678j]])

Complex-valued matrix with real e-values (but complex-valued e-vectors);
note that ``a.conj().T == a``, i.e., `a` is Hermitian.

>>> a = np.array([[1, 1j], [-1j, 1]])
>>> w, v = LA.eig(a)
>>> w; v
array([2.+0.j, 0.+0.j])
array([[ 0.        +0.70710678j,  0.70710678+0.j        ], # may vary
       [ 0.70710678+0.j        , -0.        +0.70710678j]])

Be careful about round-off error!

>>> a = np.array([[1 + 1e-9, 0], [0, 1 - 1e-9]])
>>> # Theor. e-values are 1 +/- 1e-9
>>> w, v = LA.eig(a)
>>> w; v
array([1., 1.])
array([[1., 0.],
       [0., 1.]])

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

鄱阳县| 通许县| 同江市| 白城市| 焦作市| 伊川县| 鄱阳县| 新竹县| 亳州市| 广德县| 陈巴尔虎旗| 吉木乃县| 当涂县| 西充县| 玛纳斯县| 连江县| 栾川县| 商河县| 石景山区| 泽普县| 晴隆县| 兰州市| 加查县| 镇远县| 巨野县| 临西县| 巫溪县| 奉贤区| 巴中市| 慈溪市| 临沧市| 深圳市| 昔阳县| 巫山县| 安新县| 平舆县| 新和县| 舞钢市| 阆中市| 通化县| 石台县|