欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

語(yǔ)法

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是一個(gè)矩陣Matrix的數(shù)組。每個(gè)矩陣M都會(huì)被計(jì)算其特征值與特征向量。

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是其特征值。特征值不會(huì)特意進(jìn)行排序。返回的array一般都是復(fù)數(shù)形式,除非虛部為0,會(huì)被cast為實(shí)數(shù)。當(dāng)a是實(shí)數(shù)類(lèi)型時(shí),返回的就是實(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]對(duì)應(yīng)特征值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:計(jì)算非對(duì)稱(chēng)矩陣的特征值
  • eigh:實(shí)對(duì)稱(chēng)矩陣或者復(fù)共軛對(duì)稱(chēng)矩陣(Hermitian)的特征值與特征向量
  • eigvalsh: 實(shí)對(duì)稱(chēng)矩陣或者復(fù)共軛對(duì)稱(chēng)矩陣(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.

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

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

即 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é)

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

相關(guān)文章

  • 關(guān)于pycharm中pip版本10.0無(wú)法使用的解決辦法

    關(guān)于pycharm中pip版本10.0無(wú)法使用的解決辦法

    近期在利用 pycharm 安裝第三方庫(kù)時(shí)會(huì)提示 pip 不是最新版本, 因此對(duì) pip 進(jìn)行更新,但是生成最新版本之后, pip 中由于缺少 main 函數(shù),導(dǎo)致在 pycharm 中無(wú)法自動(dòng)安裝第三方庫(kù)。本文就介紹一下如何解決
    2019-10-10
  • Python四大金剛之元組詳解

    Python四大金剛之元組詳解

    這篇文章主要介紹了Python的元組,小編覺(jué)得這篇文章寫(xiě)的還不錯(cuò),需要的朋友可以參考下,希望能夠給你帶來(lái)幫助
    2021-10-10
  • Django修改端口號(hào)與地址的三種方式

    Django修改端口號(hào)與地址的三種方式

    Django是一個(gè)開(kāi)放源代碼的Web應(yīng)用框架,由Python寫(xiě)成,下面這篇文章主要給大家介紹了關(guān)于Django修改端口號(hào)與地址的三種方式,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • Pandas中KeyError: 'Column_Name' not in index”的報(bào)錯(cuò)分析

    Pandas中KeyError: 'Column_Name' not 

    在使用Pandas進(jìn)行數(shù)據(jù)處理時(shí),KeyError: 'Column_Name' not in index是一種常見(jiàn)的錯(cuò)誤,它通常發(fā)生在嘗試訪問(wèn)DataFrame中不存在的列名時(shí),本文將深入分析這一錯(cuò)誤的原因、提供解決辦法,需要的朋友可以參考下
    2024-07-07
  • 簡(jiǎn)單介紹利用TK在Python下進(jìn)行GUI編程的教程

    簡(jiǎn)單介紹利用TK在Python下進(jìn)行GUI編程的教程

    這篇文章主要介紹了簡(jiǎn)單介紹利用TK在Python下進(jìn)行GUI編程的教程,本文來(lái)自于IBM官方開(kāi)發(fā)者技術(shù)文檔,需要的朋友可以參考下
    2015-04-04
  • python實(shí)現(xiàn)定時(shí)發(fā)送郵件

    python實(shí)現(xiàn)定時(shí)發(fā)送郵件

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)定時(shí)發(fā)送郵件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • 根據(jù)DataFrame某一列的值來(lái)選擇具體的某一行方法

    根據(jù)DataFrame某一列的值來(lái)選擇具體的某一行方法

    今天小編就為大家分享一篇根據(jù)DataFrame某一列的值來(lái)選擇具體的某一行方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-07-07
  • 如何用python做簡(jiǎn)單的接口壓力測(cè)試

    如何用python做簡(jiǎn)單的接口壓力測(cè)試

    這篇文章主要介紹了如何用python做簡(jiǎn)單的接口壓力測(cè)試問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Python利用魔法方法玩轉(zhuǎn)對(duì)象

    Python利用魔法方法玩轉(zhuǎn)對(duì)象

    Python中魔法方法(magic method)其實(shí)就是那些被雙下劃線包圍的方法,這些魔法方法為類(lèi)添加了**“魔力”,讓我們可以在面向?qū)ο缶幊讨杏酶雍?jiǎn)潔的代碼來(lái)操作對(duì)象,下面我們就來(lái)具體了解一下如何利用魔法方法玩轉(zhuǎn)對(duì)象吧
    2023-12-12
  • python基于opencv批量生成驗(yàn)證碼的示例

    python基于opencv批量生成驗(yàn)證碼的示例

    這篇文章主要介紹了python基于opencv批量生成驗(yàn)證碼的示例,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-04-04

最新評(píng)論