文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
本文主要是对比Torch与Numpy的一些操作。
1 | import torch |
numpy data: [[0 1 2]
[3 4 5]]
torch data:
0 1 2
3 4 5
[torch.LongTensor of size 2x3]
tensor2array: [[0 1 2]
[3 4 5]]
1 | # Tensor的文档:http://pytorch.org/docs/master/tensors.html |
-2
-1
0
1
2
[torch.FloatTensor of size 5]
1 | # abs操作 |
[2 1 0 1 2]
2
1
0
1
2
[torch.FloatTensor of size 5]
1 | # sin操作 |
[-0.90929743 -0.84147098 0. 0.84147098 0.90929743]
-0.9093
-0.8415
0.0000
0.8415
0.9093
[torch.FloatTensor of size 5]
1 | # mean操作 |
0.0
0.0
1 | # 矩阵相乘 |
[[ 7 10]
[15 22]]
7 10
15 22
[torch.FloatTensor of size 2x2]
7 10
15 22
[torch.FloatTensor of size 2x2]