Pytorch API接口说明

函数说明:Pytorch官网

持续更新…

torch.squeeze

torch.squeeze(input, dim=None) → Tensor
Returns a tensor with all specified dimensions of input of size 1 removed.

例如,如果input的形状为: (A×1×B×C×1×D),那么 input.squeeze() 将具有以下形状: (A×B×C×D) 。

当给出 dim 时,仅在给定的维度上进行压缩操作。如果输入的形状为: (A×1×B) ,squeeze(input, 0) 保持张量不变,但squeeze(input, 1) 会将张量压缩到形状 (A×B) 。

注意:返回的张量与输入张量共享存储,因此更改一个张量的内容将更改另一个张量的内容。

torch.unsqueeze

torch.unsqueeze(input, dim) → Tensor
Returns a new tensor with a dimension of size one inserted at the specified position.

返回的张量与该张量共享相同的基础数据。

可以使用 [-input.dim() - 1, input.dim() + 1) 范围内的dim值。负dim等效于在dim = dim + input.dim() + 1 处应用unsqueeze()。

torch.max

torch.max(input) → Tensor
Returns the maximum value of all elements in the input tensor.


>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6763,  0.7445, -2.2369]])
>>> torch.max(a)
tensor(0.7445)

torch.max(input, dim, keepdim=False, *, out=None)
Parameters:
input (Tensor) – the input tensor.
dim (int) – the dimension to reduce.
keepdim (bool) – whether the output tensor has dim retained or not. Default: False.
Keyword Arguments:
out (tuple, optional) – the result tuple of two output tensors (max, max_indices)

返回一个命名元组(values,indices),其中values是给定维度dim中输入张量每行的最大值。 indexs 是找到的每个最大值(argmax)的索引位置。

如果 keepdim 为 True,则输出张量与输入的大小相同,但维度 dim 的大小为 1。否则,dim 会被压缩,导致输出张量的维度比输入减1。

>>> a = torch.randn(4, 4)
>>> a
tensor([[-1.2360, -0.2942, -0.1222,  0.8475],
        
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

余加木

想喝蜜雪冰城柠檬水(≧≦)/

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

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

打赏作者

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

抵扣说明:

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

余额充值