torch.hstack
- torch.hstack(tensors, *, out=None) → Tensor
-
按列水平堆叠张量。
这相当于一维张量沿第一个轴连接,而其他所有张量沿第二个轴连接。
- 参数
-
tensors (张量序列) – 需要进行拼接的张量序列
- 关键字参数
-
out (Tensor, 可选) – 指定输出张量。
示例:
>>> a = torch.tensor([1, 2, 3]) >>> b = torch.tensor([4, 5, 6]) >>> torch.hstack((a,b)) tensor([1, 2, 3, 4, 5, 6]) >>> a = torch.tensor([[1],[2],[3]]) >>> b = torch.tensor([[4],[5],[6]]) >>> torch.hstack((a,b)) tensor([[1, 4], [2, 5], [3, 6]])