torch.column_stack¶
- torch.column_stack(tensors, *, out=None) Tensor ¶
透過水平堆疊
tensors
中的張量來建立一個新的張量。等同於
torch.hstack(tensors)
,除非tensors
中每個零維或一維的張量t
首先會被 reshape 成一個(t.numel(), 1)
的欄向量,然後再進行水平堆疊。- 參數
tensors (Tensors 的 sequence) – 要串接的張量序列
- 關鍵字參數
out (Tensor, optional) – 輸出的張量 (可選)。
範例
>>> a = torch.tensor([1, 2, 3]) >>> b = torch.tensor([4, 5, 6]) >>> torch.column_stack((a, b)) tensor([[1, 4], [2, 5], [3, 6]]) >>> a = torch.arange(5) >>> b = torch.arange(10).reshape(5, 2) >>> torch.column_stack((a, b, b)) tensor([[0, 0, 1, 0, 1], [1, 2, 3, 2, 3], [2, 4, 5, 4, 5], [3, 6, 7, 6, 7], [4, 8, 9, 8, 9]])