Pytorch中的view函数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wolf2345/article/details/88974388

Pytorch 中的view函数作用是将张量铺平,

例如:

import torch
target = torch.randn(10,2)
print(target)
target = target.view(1,-1)
print(target)

tensor([[ 0.4080,  0.2592],
        [-0.6065, -1.6695],
        [-0.2938,  1.0712],
        [-1.2811,  0.1640],
        [-0.1256,  0.3585],
        [-0.6682, -0.8516],
        [-1.6582,  1.2890],
        [ 0.0135,  1.5360],
        [-0.1070,  0.6072],
        [-0.1969, -0.6077]])
tensor([[ 0.4080,  0.2592, -0.6065, -1.6695, -0.2938,  1.0712, -1.2811,  0.1640,
         -0.1256,  0.3585, -0.6682, -0.8516, -1.6582,  1.2890,  0.0135,  1.5360,
         -0.1070,  0.6072, -0.1969, -0.6077]])

猜你喜欢

转载自blog.csdn.net/wolf2345/article/details/88974388
今日推荐