I have:
import numpy as np
a = np.array ([0, 1, 2], [4, 5, 6])
and now how can I transpose this matrix to get
a = [[0, 4], [1, 5], [2, 6]]
?
Answer 1, authority 100%
Transpose an array in numpy like this:
import numpy as np
a = np.array ([[0, 1, 2], [4, 5, 6]])
a = a.transpose ()
print (a)
Result:
[[0 4]
[15]
[2 6]]
Answer 2, authority 75%
import numpy as np
a = np.array ([0, 1, 2], [4, 5, 6])
a = a.T
Answer 3
def transpouse (mat):
matrix = []
for i in range (len (mat [0])): # mat is the original matrix
matrix.append (list ())
for j in range (len (mat)):
matrix [i] .append (mat [j] [i])
return matrix