From dcbedfe2370f655286e6cc27704d8f1175fb6afe Mon Sep 17 00:00:00 2001 From: Marc Partensky Date: Fri, 30 Oct 2020 19:24:33 +0100 Subject: [PATCH] torch addition --- learning-pytorch/tensor_tutorial.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/learning-pytorch/tensor_tutorial.py b/learning-pytorch/tensor_tutorial.py index 2dcf1fe..af403f9 100755 --- a/learning-pytorch/tensor_tutorial.py +++ b/learning-pytorch/tensor_tutorial.py @@ -6,8 +6,22 @@ import torch # x = torch.empty(5, 3) # x = torch.rand(5, 3) # x = torch.zeros(5, 3, dtype=torch.long) -x = torch.tensor([5.5, 3]) -x = x.new_ones(5, 3, dtype=torch.double) -print(x) -x = torch.randn_like(x, dtype=torch.float) -print(x) +# x = torch.tensor([5.5, 3]) +# x = x.new_ones(5, 3, dtype=torch.double) +# print(x) +# x = torch.randn_like(x, dtype=torch.float) +# print(x.size()) + +# y = torch.rand(5, 3) +# print(x+y) +# print(torch.add(x, y)) +# result = torch.empty(5, 3) +# torch.add(x, y, out=result) +# print(result) + +# print(x[:, 1]) + +x = torch.randn(4, 4) +y = x.view(16) +z = x.view(-1, 8) # the size -1 is inferred from other dimensions +print(x.size(), y.size(), z.size())