2013-02-25 26 views
2

当解决矩阵的逆问题时,我会遇到一个问题。 首先,我用python的numpy的库,使其通过以下编码:为什么相反的结果不相等?

import numpy as np 
mtx_str = '1 0.05336904 1.03164031 0.05505765;1 0.05248641 3.0928260 0.16233134;1 2.16503202 1.03197617 2.23426146;1 0.05347855 -1.02633768 -0.05488705' 
A = np.matrix(mtx_str) 
np.rank(A) 

其返回2;但如果我输入使用倍频软件:

A = [1 0.05336904 1.03164031 0.05505765; 1 0.05248641 3.09282607 0.16233134; 1 2.16503202 1.03197617 2.23426146; 1 0.05347855 -1.02633768 -0.05488705] 
inv(A) 

其返回4.

我不知道为什么逆结果是不同的?

回答

3

它没有很好的记载在上线numpy的参考,但是从文档字符串:

>>> help(np.rank) 
Help on function rank in module numpy.core.fromnumeric: 

rank(a) 
    Return the number of dimensions of an array. 

>>> help(np.linalg.matrix_rank) 
Help on function matrix_rank in module numpy.linalg.linalg: 

matrix_rank(M, tol=None) 
    Return matrix rank of array using SVD method 

当然的结果是相同的,如八度:

>>> np.linalg.matrix_rank(A) 
4 
+0

1:做得好。 :) – 2013-02-25 14:54:28

相关问题