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

该博客介绍了如何在Python的Numpy库中将一维行向量转换为一维列向量。通过调用transpose()函数,可以不改变原始数据而创建一个转置后的副本。例如,一个形状为(1, 256)的向量经过转置会变成形状为(256, 1)的列向量。
摘要由CSDN通过智能技术生成

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值