在Numpy中将行向量转换为列向量 [英] Transforming a row vector into a column vector in Numpy
本文介绍了在Numpy中将行向量转换为列向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个形状为(1,256)的行向量.我想将其转换为形状为(256,1)的列向量.您将如何在Numpy中做到这一点?
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 transpose operation to do this:
示例:
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]])
请注意,原始数组a
仍将保持不变.转置操作只会复制并转置.
Note that the original array a
will still remain unmodified. The transpose operation will just make a copy and transpose it.
这篇关于在Numpy中将行向量转换为列向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文