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

How to multiply many matrices in one go in python?

Suppose I have four matrices, a, b, c, and d.

In Python (with numpy), I need to do result = np.matmul(np.matmul(np.matmul(a,b),c),d) to multiply them.

In MATLAB/GNU Octave, I can multiply them in a much simpler manner, result = a*b*c*d.

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

Is there any way to multiply matrices in Python, so that I would not have to repeatedly write np.matmul avoid nested brackets?

>Solution :

Use the @ operator. result = a@b@c@d.

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