My friend and I executed this lines of code in Python 2
and Python 3
:
import numpy as np
mat = np.array([[1,0,0],[-1,3,3],[1,2,2]])
np.linalg.inv(mat)
Which returns:
array([[ 1.00000000e+00, 0.00000000e+00, 0.00000000e+00],
[ 1.50119988e+16, 6.00479950e+15, -9.00719925e+15],
[ -1.50119988e+16, -6.00479950e+15, 9.00719925e+15]])
Which is odd given:
np.linalg.matrix_rank(mat)
returns 2
, thus indicating that the matrix is not invertible.
I understand from this thread that is probably due to the way numpy and python handle floating point numbers, although my matrix consists of whole numbers.
Is there a particular reason why mat
breaks numpy's inverse implementation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…