Transpose Matrix | Linear Algebra using Python

Linear Algebra using Python | Transpose Matrix: Here, we are going to learn how to print the transpose matrix in Python?
Submitted by Anuj Singh, on May 26, 2020

Prerequisites:

The transpose of a matrix is a matrix whose rows are the columns of the original. In mathematical terms, A(i,j) becomes A(j,i) in the new matrix. Transpose has an important role in understanding and implementing Machine Learning algorithms. Major usage by Matrix Multiplication.

Transpose a matrix

Method 1:

Syntax:  
    transpose_M = M.T
Parameter: 
    Matrix M
Return: 
    MT

Method 2:

Syntax:  
    transpose_M = numpy.transpose(M)
Input Parameter: 
    Matrix M
Return: 
    MT

Python code for transpose matrix

# Linear Algebra Learning Sequence
# Transpose using different Method

import numpy as np

g = np.array([[2,3,4], [45,45,45]])
print("---Matrix g----\n", g)

# Transposing the Matrix g
print('\n\nTranspose as g.T----\n', g.T)
print('\n\nTranspose as np.tanspose(g)----\n', np.transpose(g))

Output:

---Matrix g----
 [[ 2  3  4]
 [45 45 45]]


Transpose as g.T----
 [[ 2 45]
 [ 3 45]
 [ 4 45]]


Transpose as np.tanspose(g)----
 [[ 2 45]
 [ 3 45]
 [ 4 45]]





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.