Transpose the Matrix in Numpy Python by R4R Team

Transpose of Matrix-

Example-
matrix is
[[1 2 3]
[1 1 0]]

transpose matrix is
[[1 1]
[2 1]
[3 0]]

Syntax-

array.transpose()


program-

#import numpy
import numpy as np

l=[[1,2,3],[4,5,1]]
arr=np.array(l)
print("nMatrix is :n",arr)
print("After Transpose :n",arr.transpose())

l=[[1,2,3],[4,5,1],[1,1,0]]
arr=np.array(l)
print("nMatrix is :n",arr)
print("After Transpose :n",arr.transpose())


output-

Matrix is :
[[1 2 3]
[4 5 1]]
After Transpose :
[[1 4]
[2 5]
[3 1]]

Matrix is :
[[1 2 3]
[4 5 1]
[1 1 0]]
After Transpose :
[[1 4 1]
[2 5 1]
[3 1 0]]




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!