- Related Questions & Answers
- Transpose a matrix in Python?
- How to calculate transpose of a matrix using C program?
- How to Transpose a matrix in Single line in Python?
- Java program to transpose a matrix.
- Python Program to find the transpose of a matrix
- Transpose a matrix in C#
- Transpose a matrix in Java
- Find the transpose of a matrix in Python Program
- C++ Program to Find Transpose of a Matrix
- Program to find the transpose of given matrix in Python
- Java program to print the transpose of a matrix
- C++ Program to Find Transpose of a Graph Matrix
- A C++ Program for 2d matrix for taking Transpose
- Write a program in Python to transpose the index and columns in a given DataFrame
- Transpose of a two-dimensional array - JavaScript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

When rows and columns of a matrix are interchanged, the matrix is said to be transposed. In Python, a matrix is nothing but a list of lists of equal number of items. A matrix of 3 rows and 2 columns is following list object

X = [[12,7], [4 ,5], [3 ,8]]

Its transposed appearance will have 2 rows and three columns. Using nested loops this can be achieved.

X = [[12,7], [4 ,5], [3 ,8]] result = [[0,0,0], [0,0,0]] # iterate through rows for i in range(len(X)): # iterate through columns for j in range(len(X[0])): result[j][i] = X[i][j] for r in result: print(r)

The result will be a transposed matrix

[12, 4, 3] [7, 5, 8]

Advertisements