stack¶
dragon.vm.torch.
stack
(
tensors,
dim=0,
out=None
)[source]¶Stack the inputs along the given dimension.
All the dimensions of inputs should be same:
x1 = torch.ones(2, 3) x2 = torch.zeros(2, 4) y = torch.stack([x1, x1]) # Ok z = torch.stack([x1, x2]) # Wrong
dim
can be negative:x = torch.tensor([[1, 2], [3, 4]]) y = torch.stack([x, x], dim=1) z = torch.stack([x, x], dim=-1) # Equivalent
- Parameters:
- tensors (Sequence[dragon.vm.torch.Tensor]) – The input tensors.
- dim (int, optional, default=0) – The dimension to stack.
- out (dragon.vm.torch.Tensor, optional) – The output tensor.
- Returns:
dragon.vm.torch.Tensor – The output tensor.