torch unsqueeze()详解

 Torch官网解释:

torch.unsqueeze(inputdim) → Tensor

        Returns a new tensor with a dimension of size one inserted at the specified position.

        The returned tensor shares the same underlying data with this tensor

函数的功能是将输入增加一个维度,dim决定在哪一层增加一个维度

>>> x = torch.tensor([1, 2, 3, 4])
>>> torch.unsqueeze(x, 0)
tensor([[ 1,  2,  3,  4]])
>>> torch.unsqueeze(x, 1)
tensor([[ 1],
        [ 2],
        [ 3],
        [ 4]])

以下是Stack Overflow里的样例图:

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2023年10月18日
下一篇 2023年10月18日

相关推荐