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]])