How to find transpose of a matrix in Python using NumPy

You can find the transpose of a matrix in Python using NumPy with the following code. If you want to learn Python then I will highly recommend you to read This Book.

How to find transpose of a matrix in Python using NumPy
How to find the transpose of a matrix in Python using NumPy

Transpose of a Matrix

In the following example, first, make a NumPy array and save it in variable ‘a’. Then find the transpose of matrix ‘a’ and save it in the variable ‘b’.

#import NumPy library
import numpy as np

#Make a numpy array
a = np.array([[31,22,43],[54,65,19],[10,8,98],[14,72,31]])
print(a)
print(a.shape)

#save the transpose of a in b
b = a.T
print(b)
print(b.shape)

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Top 10 Computer Vision Books with Python

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.