What is the transpose of a matrix?
Let’s say A is a matrix that has 2 rows and 3 columns.
Let’s also say that B is the transpose of matrix A.
In linear algebra, the transpose of a matrix is an operation that flips a matrix over its diagonal. As a result, the row and column indices of the matrix are switched. So, if the element in the ith row and jth column of matrix A is Ai,j and the element in the ith row and jth column of matrix B is Bi,j, then
In other words, the element in the ith row and jth column of matrix will become an element of jth row and ith column of matrix B. So, the matrix B becomes:
How to calculate the transpose of a matrix using Python NumPy?
We can use the following Python code to calculate the transpose of a matrix using Python NumPy.
import numpy A = numpy.array([[1, 2, 3], [4, 5, 6]]) print("A :\n", A) B = A.transpose() print("Transpose of A: \n", B)
Here, we are first creating a matrix using the numpy.array() function. After that we are using the transpose() function to create another matrix B that is transpose of A.
The output of the mentioned program will be:
A : [[1 2 3] [4 5 6]] Transpose of A: [[1 4] [2 5] [3 6]]
0 Comments