快捷方式

torch.atleast_2d

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

返回每个输入张量的二维视图(对于零维张量)。对于二维或更高维度的输入张量,则按原样返回。

参数

input (Tensorlist of Tensors) –

返回值

output (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.]]))

© Copyright PyTorch 贡献者。

使用 Sphinx 构建,主题由 Read the Docs 提供。

文档

查阅 PyTorch 全面的开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并解答您的疑问

查看资源