How to append to a tensor in a loop - PyTorch Forums
https://discuss.pytorch.org/t/how-to-append-to-a-tensor-in-a-loop/13555931.10.2021 · You can concatenate the tensors along the specific dimension. Your question can be briefly expressed like below, a = torch.Size (1, 3, 7) b = torch.Size (1, 3, 7) result = torch.cat ( (a, b), dim=1) Then, you can get the result tensor size of (1, 6, 7) The sample code. for i in range (it): try: a = torch.cat ( (a, new_a), dim=1) except: a = new_a.
How to append an int tensor to a list tensor? - PyTorch Forums
discuss.pytorch.org › t › how-to-append-an-intDec 23, 2020 · In python, I can use: A = [1,2] B = 3 A.append(B) to get [1,2,3]. However, In pytorch, A = torch.tensor([1,2]) B = torch.tensor(3) How to get: tensor([1,2,3]) Thank you very much
torch.Tensor.expand — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.Tensor.expand. Tensor.expand(*sizes) → Tensor. Returns a new view of the self tensor with singleton dimensions expanded to a larger size. Passing -1 as the size for a dimension means not changing the size of that dimension. Tensor can be also expanded to a larger number of dimensions, and the new ones will be appended at the front.
How to append to a tensor in a loop - PyTorch Forums
discuss.pytorch.org › t › how-to-append-to-a-tensorOct 31, 2021 · You can concatenate the tensors along the specific dimension. Your question can be briefly expressed like below, a = torch.Size (1, 3, 7) b = torch.Size (1, 3, 7) result = torch.cat ( (a, b), dim=1) Then, you can get the result tensor size of (1, 6, 7) The sample code. for i in range (it): try: a = torch.cat ( (a, new_a), dim=1) except: a = new_a.