torch.unsqueeze

unsqueeze在指定位置处插入尺寸为1的维度。

注意:返回的张量与此张量共享相同的基础数据。

Example:

>>> 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]])

 

posted on 2019-01-23 17:39  那抹阳光1994  阅读(320)  评论(0编辑  收藏  举报

导航