
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to Transpose a Matrix using Python?
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]
- Related Articles
- Transpose a matrix in Python?
- How to Transpose a matrix in Single line in Python?
- How to calculate transpose of a matrix using C program?
- Python Program to find the transpose of a matrix
- Java program to transpose a matrix.
- Find the transpose of a matrix in Python Program
- How to perform image transpose using OpenCV Python?
- Transpose a matrix in Java
- Transpose a matrix in C#
- Compute a matrix transpose with Einstein summation convention in Python
- Program to find the transpose of given matrix in Python
- C++ Program to Find Transpose of a Matrix
- Java Program to Find Transpose of a Matrix
- Java program to print the transpose of a matrix
- C++ Program to Find Transpose of a Graph Matrix

Advertisements