評價此頁

torch.atleast_2d#

torch.atleast_2d(*tensors)[原始碼]#

為每個零維輸入張量返回一個二維檢視。維度為兩維或更多的輸入張量將按原樣返回。

引數

input (TensorTensor 序列) – 要轉換為至少二維的張量。

返回

output (Tensor or tuple of Tensors)

示例

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