NumPy的Linalg线性代数库探究

    1、矩阵的行列式

    

from numpy import *    
A=mat([[1,2,4,5,7],[9,12,11,8,2],[6,4,3,2,1],[9,1,3,4,5],[0,2,3,4,1]])  
print('det(A):',linalg.det(A))  

  

det(A): -812.0  

  2、矩阵的逆

   

A=mat([[1,2,4,5,7],[9,12,11,8,2],[6,4,3,2,1],[9,1,3,4,5],[0,2,3,4,1]])

  

invA=linalg.inv(A)  
print('inv(A):',invA)

  

inv(A): [[-0.07142857 -0.01231527  0.05295567  0.09605911 -0.00862069]  
 [ 0.21428571 -0.37684729  1.22044335 -0.46059113  0.3362069 ]  
 [-0.21428571  0.82512315 -2.04802956  0.56403941 -0.92241379]  
 [ 0.         -0.4137931   0.87931034 -0.17241379  0.81034483]  
 [ 0.21428571 -0.06650246  0.18596059 -0.08128079 -0.14655172]]  

  3、矩阵的对称

   

from numpy import *  
  
A=mat([[1,2,4,5,7],[9,12,11,8,2],[6,4,3,2,1],[9,1,3,4,5],[0,2,3,4,1]])  
AT=A.T  
print(A*AT) 

  

[[ 95 131  43  78  43]  
 [131 414 153 168  91]  
 [ 43 153  66  80  26]  
 [ 78 168  80 132  32]  
 [ 43  91  26  32  30]]  

  4、矩阵的秩

   

from numpy import *   
A=mat([[1,2,4,5,7],[9,12,11,8,2],[6,4,3,2,1],[9,1,3,4,5],[0,2,3,4,1]])  
print(linalg.matrix_rank(A))  

  

posted @ 2018-03-14 08:57  圆柱模板  阅读(223)  评论(0编辑  收藏  举报