首页 > 编程知识 正文

pytorch怎么注释多行代码,怎么打印pytorch的初始化权重

时间:2023-05-04 15:44:43 阅读:192639 作者:3977

1、使用 None 增加 tensor 的维度

在维度中使用 None 可以在所在维度中增加一维。

2、使用 unsqueeze() 增加 tensor 的维度

torch.unsqueeze(input, dim) → Tensor
torch.Tensor.unsqueeze(dim) → Tensor

参数:input:input tensor.dim:在 dim 所在的索引位置插入一个新的维度,索引范围在 [-input.dim() - 1, input.dim() + 1) 之间。

3、使用 squeeze() 压缩 tensor 的维度

torch.squeeze(input, dim=None) → Tensor
torch.Tensor.squeeze(dim=None) → Tensor

参数:input:input tensor.dim:要压缩的维度索引,如果 dim 为 None,则压缩 input tensor 中所有维度为 1 的维度,如果 dim 指定,则当 dim 索引所在的维度为1时,只压缩该维度,当 dim 索引所在的维度不为1时,不做压缩。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。