2

I mat a problem when solving inverse of a matrix. Firstly, I use python numpy library to make it, by coding below:

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)

it return 2; but if I use octave software by entering:

  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)

it return 4.

I wonder why the inverse result is different?

Shai
  • 111,146
  • 38
  • 238
  • 371
xunzhang
  • 2,838
  • 6
  • 27
  • 44

1 Answers1

3

It is not well documented on the on-line numpy reference, but from the docstrings :

>>> 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

And of course the result is the same as in Octave:

>>> np.linalg.matrix_rank(A)
4
Jaime
  • 65,696
  • 17
  • 124
  • 159