[英]Tensor of Lists: how to convert to tensor of one list?
我有這樣的張量
tensor([[4.],[1.]], device='cuda:0')
我想更改為以下內容:
tensor([4.,1.], device='cuda:0')
怎么做?
我不確定這是否是錯誤的原因:
loss = nn.MSELoss(y_tilde,y)
RuntimeError: Boolean value of Tensor with more than one value is ambiguous
使用
torch.flatten()
例子:
t = torch.tensor([[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]]])
out: tensor([[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]]])
torch.flatten(t)
out: tensor([1, 2, 3, 4, 5, 6, 7, 8])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.