python将一列数据转换成向量_在Numpy中将行向量转换为列向量

1586010002-jmsa.png

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.

你可能感兴趣的:(python将一列数据转换成向量_在Numpy中将行向量转换为列向量)