The first article is here: NumPy Library Advanced Tutorial (i) solving a linear equation group
Solving eigenvalues and eigenvectors
For an introduction to eigenvalues and eigenvectors, click here
First create a matrix
In [1]: A=mat("3 -2;1 0")In [2]: AOut[2]: matrix([[ 3, -2], [ 1, 0]])
In the Numpy.linalg module, the Eigvals function calculates the eigenvalues of the Matrix, and the EIG function can return a tuple containing the eigenvalues and corresponding eigenvectors.
Using the Eigvals function to solve eigenvalue values
In[3]linalg.eigvals(A)Out[3]array([ 2., 1.])
Use the EIG function to solve eigenvalues and eigenvectors. The function returns a tuple, which discharges the eigenvalues and corresponding eigenvectors, where the first column is the eigenvalues and the second column is the eigenvector.
In [5]: B=eig(A)In [6]: BOut[62., 1.]), matrix([[ 0.89442719, 0.70710678], [ 0.4472136 , 0.70710678]]))
Using the DOT function to verify that the solution is correct by multiplying the matrix
eigenvalues, eigenvectors = np.linalg.eig(A)print"First tuple of eig", eigenvaluesprint"Second tuple of eig\n", eigenvectorsforin range(len(eigenvalues)): print"Left", np.dot(A, eigenvectors[:,i]) print"Right", eigenvalues[i] * eigenvectors[:,i] print
Output to
[[ 1.78885438] [ 0.89442719]][[ 1.78885438] [ 0.89442719]][[ 0.70710678] [ 0.70710678]][[ 0.70710678] [ 0.70710678]]
Calculation Matrix determinant
In [51]: A = np.mat("3 4;5 6")In [52print"A\n", AA[[3 4] [5 6]]
Use the DET function to calculate the determinant
In [53"Determinant", np.linalg.det(A)Determinant -2.0
NumPy Library Advanced Tutorial (ii)