x = torch.tensor([1, 2, 3])
print(x)
# some operatons?
print(x)
出局:
tensor([[ 1, 2, 3]])
tensor([[ 1, 2, 3, 4]])
我尝试过tensor.expand()方法,但没有成功...
答案 0 :(得分:0)
我找到解决方法...
>>> x = torch.tensor([[1, 2, 3]])
>>> print(x)
>>> print(x.size())
tensor([[1, 2, 3]])
torch.Size([1, 3])
>>> x = x.repeat_interleave(torch.tensor([1, 1, 2]))
>>> print(x)
>>> print(x.size())
tensor([1, 2, 3, 3])
torch.Size([4])
>>> x[3] = 4
>>> x = x.unsqueeze(0)
>>> print(x)
>>> print(x.size())
tensor([[1, 2, 3, 4]])
torch.Size([1, 4])