Let's say I have a row vector of the shape (1, 256). I want to transform it into a column vector of the shape (256, 1) instead. How would you do it in Numpy?
解决方案
you can use the
Example:
In [2]: a = np.array([[1,2], [3,4], [5,6]])
In [5]: np.shape(a)
Out[5]: (3, 2)
In [6]: a_trans = a.transpose()
In [8]: np.shape(a_trans)
Out[8]: (2, 3)
In [7]: a_trans
Out[7]:
array([[1, 3, 5],
[2, 4, 6]])
Note that the original array a will still remain unmodified. The transpose operation will just make a copy and transpose it.