List of list of tensors to tensor

Hi,

is there a way to get this running?

trans_matrix = torch.tensor([
    [
     trans_params[:, 1] * torch.cos(trans_params[:, 0]), 
     trans_params[:, 1] * -1 * torch.sin(trans_params[:, 0]), 
     trans_params[:, 2]
    ], [
     trans_params[:, 1] * torch.sin(trans_params[:, 0]), 
     trans_params[:, 1] * torch.cos(trans_params[:, 0]),
     trans_params[:, 3]
   ]
])

The code gives me this error:

ValueError: only one element tensors can be converted to Python scalars

I know that the problem is that I have lists of lists of tensors and this cannot easily be converted to one tensor. But is there any other possibility how I can achieve this? I can’t find a solution other than using a loop and constructing the new tensor, but this would probably be very slow and not run on the GPU

Have you looked into torch.cat? This can help you convert a list of tensors into a single one.