numpy singular value decomposition, generalized inverse matrix and determinant

SVD

Factoring the product of one kind of operation is the matrix into a matrix 3

Among them, the singular value matrix is ​​a diagonal matrix

 

Key_Function

np.linalg.svd function, may be the singular value decomposition of the matrix.

  U: orthogonal matrix

  sigma: An array of singular value diagonal matrix, other off-diagonal elements are 0

  V: orthogonal matrix

np.diag function, draw a complete matrix of singular values

Code

Import numpy NP AS 

A = np.mat ( " . 4 14. 11; -2. 8. 7 " )
 Print (A)
 '' ' 
[[14. 4. 11] 
 [-2. 8. 7]] 
' '' 

the U-, Sigma, V = np.linalg.svd (A, full_matrices = False)
 Print (the U-)
 '' ' 
[[-0.9486833 -0.31622777] 
 [-0.31622777 .9486833]] 
' '' 
Print (Sigma)     # the Sigma only the diagonal matrix of singular values value 
'' ' 
[18.97366596 9.48683298] 
' '' 
Print (np.diag (Sigma))
 '' ' 
[[18.97366596 of 0. the] 
 [of 0. the. 9.48683298]]
'''
print(V)
 '' ' 
[[-0.33333333 -0.66666667 -0.66666667] 
 [0.66666667 0.33333333 -0.66666667]] 
' '' 

print (U * np.diag (Sigma) * V)
 '' ' 
[[4. 11. 14.] 
 [8. 7. -2].] 
'' '

 

Generalized inverse matrix

Key_Function

np.linalg.pinv function

np.inv function

Code

Import numpy NP AS 

A = np.mat ( " . 4 14. 11; -2. 8. 7 " )
 Print (A)
 '' ' 
[[14. 4. 11] 
 [-2. 8. 7]] 
' '' 

pseudoinv = np.linalg. Pinv (A)
 Print (pseudoinv)
 '' ' 
[[-0.00555556 .07222222] 
 [0.02222222 .04444444] 
 [0.05555556 -0.05555556]] 
' '' 

Print (A * pseudoinv)
 '' ' is very close to the unit matrix 
[[1.00000000e + 00 0.00000000 00 + E] 
 [8.32667268e-1.00000000e. 17 + 00]] 
'' '

 

 

Mathematical concepts

The definition of generalized inverse matrix

or

 

Solving the generalized inverse matrix

 

Determinant

Key_Function

Np.linalg.det determinant function calculation matrix

Code

import numpy as np

A = np.mat("3 4; 5 6")
print(A)
'''
[[3 4]
 [5 6]]
'''

print(np.linalg.det(A))
# -2.0

 

Guess you like

Origin www.cnblogs.com/draven123/p/11410045.html