Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Right matrix division in NumPy, any better way than np.linalg.inv()?

What is the fastest way of doing right matrix division, i.e. xA = B in pyhton numpy? A and B are (NxN) square matrices and A is invertible, I thus want to compute equation x = BA^{-1}.

I am asking because for the left matrix division , Ax = B, x = A^{-1}B, using x = np.linalg.solve(A,B) is preferred to x = np.linalg.inv(A) @ B because of speed reasons.

But I have not found a way how to do this for the right matrix division. Right now I use x = B @ np.linalg.inv(A) Is there any better (= faster) way of doing this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Simply use numpy.linalg.solve to solve the transposed equation A.T x.T = B.T:

x = np.linalg.solve(A.T, B.T).T
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading