文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
本文主要是PyTorch中Variable变量的一些用法。
1 | import torch |
1 2
3 4
[torch.FloatTensor of size 2x2]
Variable containing:
1 2
3 4
[torch.FloatTensor of size 2x2]
1 | # 计算x^2的均值 |
7.5
Variable containing:
7.5000
[torch.FloatTensor of size 1]
1 | # variable进行反向传播 |
Variable containing:
0.5000 1.0000
1.5000 2.0000
[torch.FloatTensor of size 2x2]
1 | # *表示逐元素点乘,不是矩阵乘法 |
1 4
9 16
[torch.FloatTensor of size 2x2]
Variable containing:
1 4
9 16
[torch.FloatTensor of size 2x2]
1 | # 输出variable中的data, data是tensor |
1 2
3 4
[torch.FloatTensor of size 2x2]