Python Program to Find Transpose of Matrix

« Previous Program Next Program »

Find Transpose of Matrix in Python

To find transpose of a matrix in python, just choose a matrix which is going to transpose, and choose another matrix having column one greater than the previous matrix and row one less than the matrix. Initially second matrix will be empty matrix. Now find the transpose of matrix and print the transpose result as output.

Python Programming Code to Find Transpose of Matrix

Following python program shows how to find and print the transpose of a matrix:

# Python Program - Find Transpose of a Matrix

matrix = [[1, 2],
  [3, 4],
  [5, 6]]
rmatrix = [[0, 0, 0],
   [0, 0, 0]]
for i in range(len(matrix)):
    for j in range(len(matrix[0])):
        rmatrix[j][i] = matrix[i][j]
for r in rmatrix:

Transpose of a matrix can be calculated as exchanging row by column and column by row's elements, for example in above program the matrix contains all its elements in following ways:

Now the transpose of the above matrix can be done in this way:

Here is the sample run of the above python program:

transpose matrix python

Below is same program on python shell:

python find transpose of matrix

Same Program in Other Languages

Python Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.