2013-02-25 28 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

相關問題