torch.functional.atleast_1d#
- torch.functional.atleast_1d(*tensors)[源代码]#
返回每个输入张量的至少一维视图,其中零维张量将变为一维。具有一维或多维的输入张量将按原样返回。
- 参数
input (Tensor 或 Tensor 序列) – 要转换为至少一维的张量。
- 返回
output (Tensor or tuple of 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.])) >>> torch.atleast_1d() ()