评价此页

torch.functional.atleast_2d#

torch.functional.atleast_2d(*tensors)[source]#

为零维的每个输入张量返回一个二维视图。维度大于或等于二维的输入张量将按原样返回。

参数

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