torch.column_stack¶
- torch.column_stack(tensors, *, out=None) Tensor¶
透過水平堆疊
tensors中的張量建立一個新的張量。等效於
torch.hstack(tensors),但tensors中的每個零維或一維張量t會先被重塑為(t.numel(), 1)列,然後進行水平堆疊。- 引數
tensors (張量序列) – 要連線的張量序列
- 關鍵字引數
out (張量, 可選) – 輸出張量。
示例
>>> 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]])