2

I have a Pytorch code which generates a Pytorch tensor in each iteration of for loop, all of the same size. I want to assign each of those tensors to a row of new tensor, which will include all the tensors at the end. In other works something like this

for i=1:N: X = torch.Tensor([[1,2,3], [3,2,5]]) #Y is a pytorch tensor Y[i] = X 

I wonder how I can implement this with Pytorch.

1 Answer 1

1

You can concatenate the tensors using torch.cat:

tensors = [] for i in range(N): X = torch.tensor([[1,2,3], [3,2,5]]) tensors.append(X) Y = torch.cat(tensors, dim=0) # dim 0 is the rows of the tensor 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.