torch unsqueeze()详解
pytorch unsqueeze函数总结
文章共185字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
torch.unsqueeze(input, dim) → Tensor
Returns a new tensor with a dimension of size one inserted at the specified position.
The returned tensor shares the same underlying data with this tensor
函数的功能是将输入增加一个维度,dim决定在哪一层增加一个维度
>>> x = torch.tensor([1, 2, 3, 4])
>>> torch.unsqueeze(x, 0)
tensor([[ 1, 2, 3, 4]])
>>> torch.unsqueeze(x, 1)
tensor([[ 1],
[ 2],
[ 3],
[ 4]])
以下是Stack Overflow里的样例图:
更多推荐
已为社区贡献1条内容
所有评论(0)