tensor 增加一维度_Pytorch之Tensor操作

本文介绍了Pytorch中用于处理Tensor维度的几种方法,包括flatten、reshape、squeeze、unsqueeze、cat、view和transpose。重点讨论了reshape和view函数的区别,强调了它们在返回视图和复制数据方面的不同行为,以及何时可以安全地进行不复制的数据视图操作。
摘要由CSDN通过智能技术生成

a1c9ed5352d946c83dea30914100fedd.png

1. torch.flatten(input,start_dim=0,end_dim=-1)

2.torch.reshape(input,shape)

3.torch.squeeze(input, dim=None, out=None)

4.torch.unsqueeze(input, dim)

5.torch.cat(tensors, dim=0, out=None)

6.view(*shape)

7.torch.transpose(input, dim0, dim1)

下面记录一下reshape和view函数的区别:

  • reshape():Returns a tensor with the same data and number of elements as input, but with the specified shape. When possible, the returned tensor will be a view of input. Otherwise, it will be a copy. Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior.See torch.Tensor.view()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值