Insert an element to tensor

Hi,

How could I do this?

values = [[1, 2, 3], [9, 8, 7]]

ex = torch.zeros([2, 5], dtype=torch.int32)

Before
tensor([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]], dtype=torch.int32)

After
tensor([[0, 0, 0, 0, 0, 1, 2, 3],
[0, 0, 0, 0, 0, 9, 8, 7]], dtype=torch.int32)

You can do something like this

x = torch.cat([ ex, torch.tensor(values)], dim=1)
1 Like