torch.hstack¶
- torch.hstack(tensors, *, out=None) Tensor ¶
按水平方向(按列)依次堆叠张量。
对于一维张量,这等价于沿第一个轴进行拼接;对于所有其他张量,则等价于沿第二个轴进行拼接。
- 参数
tensors (Tensor 序列) – 需要拼接的张量序列
- 关键字参数
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]])