torch.atleast_2d

torch.atleast_2d(*tensors)[源代码]

返回每个输入张量的二维视图,即使其维度为零也一样。对于两个或更多维度的输入张量,则直接返回原张量。

参数

输入 (Tensor列表 of Tensors) –

返回值

输出 ( tensor 或 tensor 元组 )

示例:

>>> 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.]]))
本页目录