評價此頁

torch.atleast_3d#

torch.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()
()