【Pytorch】unsqueeze() 方法

您所在的位置:网站首页 torchtensor作用 【Pytorch】unsqueeze() 方法

【Pytorch】unsqueeze() 方法

2023-01-18 06:29| 来源: 网络整理| 查看: 265

文章目录 一、unsqueeze() 方法 二、实例 参考链接 一、unsqueeze() 方法 unsqueeze() 方法起升维的作用,参数表示在哪个地方加一个维度。

二、实例 import torch input=torch.arange(0,6) print(input) print(input.shape)

print(input.unsqueeze(0))    # 在0维处加一维 print(input.unsqueeze(0).shape)

print(input.unsqueeze(1))    # 在1维处加一维 print(input.unsqueeze(1).shape)   输出结果:

tensor([0, 1, 2, 3, 4, 5]) torch.Size([6]) tensor([[0, 1, 2, 3, 4, 5]]) torch.Size([1, 6])  # 在0维处加了一维 tensor([[0],         [1],         [2],         [3],         [4],         [5]]) torch.Size([6, 1])  # 在1维处加了一维   参考链接 pytorch中unsqueeze()函数理解 ———————————————— 版权声明:本文为CSDN博主「想变厉害的大白菜」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/weixin_44211968/article/details/128223412



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3