torch常用函数手册(10-20)

索引、切片、连接、换位

torch.cat()

torch.cat(inputs, dimension=0) → Tensor

在给定维度上对输入张量序列seq进行连接操作.
torch.cat()可以看做 torch.split() 和 torch.chunk()的反操作。 cat() 函数
可以通过下面例子更好的理解
参数:

  • inputs (sequence of Tensors) 可以是任意相同的Tensor类型的python序列。
  • dimension (int, optional) –沿着此维连接张量序列。

torch.chunk

torch.chunk(tensor, chunks, dim=0)

在给定维度上将输入张量进行分块儿。
参数:

  • tensor (Tensor) – 待分块的输入张量
  • chunks (int) – 分块的个数
  • dim (int) – 沿着此维度进行分块

torch.gather

torch.gather(input, dim, index, out=None) → Tensor

沿给定轴dim,将输入的索引张量index,指定位置的值进行聚合。
参数

  • input (Tensor) – 源张量
  • dim (int) – 索引的轴
  • index (LongTensor) – 聚合元素的下标
  • out (Tensor, optional) – 目标张量

torch.index_select

torch.index_select(input, dim, index, out=None) → Tensor

沿着指定维度对输入进行切片,取index中指定的相应项数。((index 为一个 LongTensor)然后返回到一个新的张量,返回的张量与原始张量_Tensor**_有相同的维度(在指定轴上)**
注意:返回的张量不与原始张量共享内存空间**。**
参数:

  • input (Tensor) – 输入张量
  • dim (int) – 索引的轴
  • index (LongTensor) – 包含索引下标的一维张量<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

big_matster

您的鼓励,是给予我最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值