I've been facing an interesting python problem. I've tried to inverse 3x3 matrix A
[[1 2 3]
[4 5 6]
[7 8 9]]
and then multiply it on initial one: A⁻ⁱA. Instead of identity matrix (with all diagonal elements equal one) I've got this one:
[[ 12. 8. 8.]
[-16. -8. 0.]
[ 4. 0. 0.]]
The problem occurs only in this specific case. Matrices with other values give right results. Here is the code:
import numpy as np
np.set_printoptions(precision=2,suppress=True)
A = np.array([1,2,3,4,5,6,7,8,9])
A = A.reshape(3,3)
print(A)
print(np.linalg.det(A))
print(np.matmul(np.linalg.inv(A),A))
Output:
[[1 2 3]
[4 5 6]
[7 8 9]]
6.66133814775094e-16
[[ 12. 8. 8.]
[-16. -8. 0.]
[ 4. 0. 0.]]