pytorch / 2 / generated / torch.dstack.html

torch.dstack

torch.dstack(tensors, *, out=None) → Tensor

Stack tensors in sequence depthwise (along third axis).

This is equivalent to concatenation along the third axis after 1-D and 2-D tensors have been reshaped by torch.atleast_3d().

Parameters

tensors (sequence of Tensors) – sequence of tensors to concatenate

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.dstack((a,b))
tensor([[[1, 4],
         [2, 5],
         [3, 6]]])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.dstack((a,b))
tensor([[[1, 4]],
        [[2, 5]],
        [[3, 6]]])

© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.dstack.html