Articles

Program to find transpose of a matrix in Python

Program to find transpose of a matrix in Python


In the python programming article, we are going to learn

  • program to find transpose of a matrix in python

Program to find transpose of a matrix in Python

The program to find transpose of a matrix in python is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

mat1 = [[1,2,3],
        [4,5,6],
        [7,8,9]]

result = list()
temp = list()

for i in range(3):
    temp = []
    for j in range(3):
        temp.append(mat1[j][i])
    result.append(temp)

for i in result:
    print(i)

The output of the transpose of a matrix in python using list is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py                        
[1, 4, 7]
[2, 5, 8]
[3, 6, 9]

Few important tips about the program

1. By transposing a matrix we mean we interchange the rows to columns and vice versa.

2. We take help of indexing while doing this.

 

Program to find transpose of a matrix in python snapshot is given below:

program to find transpose of a matrix in python

This wraps up our session on transpose of a matrix in python using list or transpose of a matrix in python with user input.


Python Matrix Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Jan 12,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!