评价此页

torch.functional.atleast_3d#

torch.functional.atleast_3d(*tensors)[源代码]#

返回每个输入张量的3维视图,其中零维被填充。具有三个或更多维度的输入张量将按原样返回。

参数

input (TensorTensor序列) – 要转换为至少3维的张量。

返回

output (Tensor or tuple of Tensors)

示例

>>> x = torch.tensor(0.5)
>>> x
tensor(0.5000)
>>> torch.atleast_3d(x)
tensor([[[0.5000]]])
>>> y = torch.arange(4).view(2, 2)
>>> y
tensor([[0, 1],
        [2, 3]])
>>> torch.atleast_3d(y)
tensor([[[0],
         [1]],

        [[2],
         [3]]])
>>> x = torch.tensor(1).view(1, 1, 1)
>>> x
tensor([[[1]]])
>>> torch.atleast_3d(x)
tensor([[[1]]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.0)
>>> torch.atleast_3d((x, y))
(tensor([[[0.5000]]]), tensor([[[1.]]]))
>>> torch.atleast_3d()
()