torch.hstack¶
- torch.hstack(tensors, *, out=None) Tensor ¶
將 tensors 依序水平堆疊 (column wise)。
對於 1-D tensors,這等同於沿著第一個軸 (axis) 串聯 (concatenation);對於所有其他 tensors,則等同於沿著第二個軸串聯。
- 參數 (Parameters)
tensors (Tensors 的序列) – 要串聯的 tensors 序列
- 關鍵字參數 (Keyword Arguments)
out (Tensor, optional) – 輸出 tensor (可選)。
範例 (Example)
>>> 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]])