Home > Tips & Tricks > Transpose of a Matrix in Python

Transpose of a Matrix in Python

A matrix in python is a rectangular array packed with symbols, expressions, alphabets, and numbers that are arranged in rows and columns but we can transpose it.

Transpose matrix means, rows will become columns and columns become rows. We can do this with the python NumPy function transpose() and creating a loop structure that iterates through the elements in the matrix and moves them around. It is very messing to design the loop structure and to replace the array elements with rows and columns.

But in this tutorial, we will do this without NumPy and without any array looping. We will use this tricky function to achieve it. Let’s see it.

In the above, we used zip() function to grouped the array with their respective elements. And used the * operator to unzip the array.

So when we run this python code then you will get the transpose matrix as an output.


[(23, 37, 14), (56, 78, 24)]

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment