Concatenate a tensor to another in PyTorch
Solution 1:
perhaps not the most straight forward approach, but nonetheless - you can use torch.cat
on x.T
once you vectorized temp
:
temp_vec = temp * torch.ones(x.shape[0])
torch.cat((x.T,temp_vec)).T
testing it out for a smaller x
(to not clutter the answer):
x = torch.Tensor([[0.0, 0.0, 0.0],
[0.0, 0.0, 0.0]])
out:
tensor([[ 0., 0., 0., 298.],
[ 0., 0., 0., 298.]])
last note: if I'm not mistaken, the transpose .T
is a field of every tensor, so using it isn't inefficient per se