1

I'm using matrices in numpy python. I have a matrix A and I then I calculate its inverse. Now I multiply A with its inverse, and I'm not getting the identity matrix. Can anyone point out what's wrong here?

A = matrix([
        [4, 3],
        [3, 2]
        ]);

print (A.I)        # prints [[-2  3], [ 3 -4]] - correct
print A.dot(A.T)   # prints [[25 18], [18 13]]     - Incorrect
print A*(A.T)      # prints [[25 18], [18 13]]     - Incorrect

2 Answers 2

4

You are using dot on the matrix and the transposed matrix (not the inverse) ...

In [16]: np.dot(A.I, A)
Out[16]:
matrix([[ 1.,  0.],
        [ 0.,  1.]])

With the transposed you have the result you showed:

In [17]: np.dot(A.T, A)
Out[17]:
matrix([[25, 18],
        [18, 13]])
1

Here is another method:

I works only on matrix

you can use np.linalg.inv(x) for inverse

In [11]: import numpy as np

In [12]: A = np.array([[4, 3], [3, 2]])

In [13]: B = np.linalg.inv(A)

In [14]: A.dot(B)
Out[14]: 
array([[ 1.,  0.],
       [ 0.,  1.]])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.