+3 votes
in Programming Languages by (73.8k points)
I want to convert the rows to columns and vice versa. How can I do?

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

First convert your matrix to Numpy array and then use transpose. Check the following example.

>>> import numpy as no

>>> a=no.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])

>>> a

array([[ 1,  2,  3,  4],

       [ 5,  6,  7,  8],

       [ 9, 10, 11, 12]])

>>> a.T

array([[ 1,  5,  9],

       [ 2,  6, 10],

       [ 3,  7, 11],

       [ 4,  8, 12]])

>>>


...