pytorch view()函数

    a=torch.Tensor([[[1,2,3],[4,5,6]]])
    b=torch.Tensor([1,2,3,4,5,6])

    print(a.view(1,6))
    print(b.view(1,6))

得到的结果都是tensor([[1., 2., 3., 4., 5., 6.]])

再看一个例子:

    a=torch.Tensor([[[1,2,3],[4,5,6]]])
    print(a.view(3,2))

将会得到:

    tensor([[1., 2.],
            [3., 4.],
            [5., 6.]])

 

猜你喜欢

转载自blog.csdn.net/qq_16792139/article/details/114403058