Python Program to Transpose a Matrix
Transpose Matrix:
If you change the rows of a matrix with the column of the same matrix, it is known as transpose of a matrix. It is denoted as X’. For example: The element at ith row and jth column in X will be placed at jth row and ith column in X’.
Let’s take a matrix X, having the following elements:
- X = [[1,2],
- [4,5],
- [7,8]]
See this example:
- X = [[1,2],
- [4,5],
- [7,8]]
- Result = [[0,0,0],
- [0,0,0]]
- # iterate through rows
- for i in range(len(X)):
- for j in range(len(X[0])):
- result[j][i] = X[i][j]
- for r in result:
- print(r)
Output: