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.
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)): rmatrix[j][i] = matrix[i][j] for r in rmatrix: print(r)
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:
Below is same program on python shell:
You may also like to learn or practice the same program in other popular programming languages: