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]] 

?

  • As it turned out with the transposition of this kind of matrix there are no problems, a.transpose () returns the result. With transposition of a one-dimensional vector, problems arise, i.e. of this type a = np.array ([[0, 1, 2]]) - lao712
  • and what problems with a one-dimensional vector? Tried, it turns out array([[1], [2], [3]]) . - insolor
  • the result is the same 1x3, and not how I would like 3x1, - lao712
  • [[1], [2], [3]] - this is 3x1 (three lines one by one). - insolor
  • By the way, since you yourself have found the answer about transposing, add it. - insolor

2 answers 2

Transposing an array into numpy is done like this:

 import numpy as np a = np.array([[0, 1, 2], [4, 5, 6]]) a = a.transpose() print(a) 

Result:

 [[0 4] [1 5] [2 6]] 
  • aT transposed view returns. - jfs
 import numpy as np a = np.array([0, 1, 2], [4, 5, 6]) a = aT 
  • 6
    Please try to leave a little more detailed answers. You can add an answer by clicking edit - aleksandr barakin