Home » Tip Bank » Web Development
  • Comment on this Article
Language: Semantic Web
Expertise: Intermediate
Mar 27, 2020

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Watch

Transpose a Matrix in Python

One of the inbuilt libraries in Python is zip. It can be utilized to transpose a matrix by performing an Unzip followed by zip as shown below.

The "zip()" function returns an iterator of tuples based on the "iterable" object. In order to get the transpose of the matrix, first, we need to unzip the list using "*"operator then zip it.

inputMatrix = [ [7, 14, 21], [1, 2, 3] ]
zip(*inputMatrix)

Output will be as follows:

[ (7, 1), (14, 2), (21, 3) ]
Srinath M S
 
Submit a Tip
Browse "Web Development" Tips
Browse All Tips
eloquentjavascript.net
codeschool.com