Transpose of a matrix is an operation in which we convert the rows of the matrix in column and column of the matrix in rows. The general equation for performing the transpose of a matrix is as follows.
Aij = Aji where i is not equal to j
Example:
Matrix M ---> [1, 8, 9
12, 6, 2
19, 42, 3]
Transpose of M
Output ---> [1, 12, 19
8, 6, 42,
9, 2, 3]
Transpose of a Matrix can be performed in two ways:
- Finding the transpose by using the t() function
Python3
M < - matrix( 1 : 6 , nrow = 2 )
print (M)
t < - t(M)
print (t)
|
[, 1] [, 2] [, 3]
[1, ] 1 3 5
[2, ] 2 4 6
[, 1] [, 2]
[1, ] 1 2
[2, ] 3 4
[3, ] 5 6
- By iterating over each value using Loops:
Python3
Matrix = matrix( 1 : 9 , nrow = 3 )
print (Matrix)
M2 = Matrix
for (i in 1 :nrow(M2))
{
for (j in 1 :ncol(M2))
{
M2[i, j] < - Matrix[j, i]
}
}
print (M2)
|
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
Last Updated :
27 Apr, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...