torch.dstack
- torch.dstack(tensors, *, out=None) → Tensor
-
沿第三轴按顺序堆叠张量(深度方向)。
这相当于先将1D和2D张量通过
torch.atleast_3d()
重新塑造为至少3D张量,然后再沿第三个轴进行拼接。- 参数
-
tensors (张量序列) – 需要进行拼接的张量序列
- 关键字参数
-
out (Tensor, 可选) – 指定输出张量。
示例:
>>> a = torch.tensor([1, 2, 3]) >>> b = torch.tensor([4, 5, 6]) >>> torch.dstack((a,b)) tensor([[[1, 4], [2, 5], [3, 6]]]) >>> a = torch.tensor([[1],[2],[3]]) >>> b = torch.tensor([[4],[5],[6]]) >>> torch.dstack((a,b)) tensor([[[1, 4]], [[2, 5]], [[3, 6]]])