torch.column_stack#
- torch.column_stack(tensors, *, out=None) Tensor#
透過水平堆疊
tensors中的張量來建立新張量。等同於
torch.hstack(tensors),不同之處在於tensors中的每個零維或一維張量t會先被重塑為(t.numel(), 1)列,然後再進行水平堆疊。- 引數
tensors (sequence of Tensors) – 要連線的張量序列
- 關鍵字引數
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]])