美文网首页
pytorch view 2021-11-06

pytorch view 2021-11-06

作者: 远方的飞鱼 | 来源:发表于2021-12-02 15:49 被阅读0次

    Tensor.view(*shape) -> Tensor
    returns a new tensor with the same data as the self tensor but of a different shape

    x = torch.randn(4, 4)
    x.size()
    output: torch.Size([4,4])

    y = x.view(16)
    y.size()
    output: torch.Size([16])

    z = x.view(-1, 8) # the size -1 is inferred from other dimensions
    z.size()
    output: torch.Size([2,8])

    a = torch.randn(1, 2, 3, 4)
    a.size()
    b = a.transpose(1, 2) # Swaps 2nd and 3rd dimension
    b.size()
    c = a.view(1, 3, 2, 4) # Does not change tensor layout in memory
    c.size()
    torch.equal(b, c)

    相关文章

      网友评论

          本文标题:pytorch view 2021-11-06

          本文链接:https://www.haomeiwen.com/subject/ooqszltx.html