torch.atleast_1d
- torch.atleast_1d(*tensors)[源代码]
-
返回每个输入张量的零维度的一维视图。对于具有一个或多个维度的输入张量,将其原样返回。
示例:
>>> x = torch.arange(2) >>> x tensor([0, 1]) >>> torch.atleast_1d(x) tensor([0, 1]) >>> x = torch.tensor(1.) >>> x tensor(1.) >>> torch.atleast_1d(x) tensor([1.]) >>> x = torch.tensor(0.5) >>> y = torch.tensor(1.) >>> torch.atleast_1d((x, y)) (tensor([0.5000]), tensor([1.]))