Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I'm trying to create a matrix transpose function in Python. A matrix is a two-dimensional array, represented as a list of lists of integers. For example, the following is a 2X3 matrix (meaning the height of the matrix is 2 and the width is 3):

A=[[1, 2, 3], 

  [4, 5, 6]]

To be transposed the jth item in the ith index should become the ith item in the jth index. Here's how the above sample would look transposed:

>>> transpose([[1, 2, 3], 

[4, 5, 6]]) 

[[1, 4], 

[2, 5], 

[3, 6]] 

>>> transpose([[1, 2], 

    [3, 4]]) 

[[1, 3], 

[2, 4]]

How can I do this?

1 Answer

0 votes
by (106k points)

You can use the below-mentioned code to see how to transpose a matrix in Python:-

import numpy as np 

a = np.array([(1,2,3), (4,5,6)]) 

b = a.transpose()

To know more about this you can have a look at the following video tutorial:-

Browse Categories

...