You can use either flatten() or reshape() to convert a 2D tensor into a 1D tensor.
Using flatten()
>>> import torch>>> a=torch.tensor([[1,2,3],[4,5,6]])>>> atensor([[1, 2, 3], [4, 5, 6]])>>> a.flatten()tensor([1, 2, 3, 4, 5, 6])
Using reshape()
>>> atensor([[1, 2, 3], [4, 5, 6]])>>> a.reshape(-1,)tensor([1, 2, 3, 4, 5, 6])
>>> atensor([[1, 2, 3], [4, 5, 6]])
>>> a.reshape(-1,)tensor([1, 2, 3, 4, 5, 6])