torch.column_stack

torch.column_stack(tensors, *, out=None) Tensor

通过将tensors中的张量水平堆叠,创建一个新的张量。

相当于torch.hstack(tensors),除了tensors中的每个零维或一维张量t首先会被重塑为(t.numel(), 1)的列,在水平堆叠之前。

参数

tensors (张量序列) – 需要进行拼接的张量序列

关键字参数

out (Tensor, 可选) – 指定输出张量。

示例:

>>> 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]])
本页目录