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