oneflow.atleast_2d

oneflow.atleast_2d(*tensors)Tensor or List[Tensor]

Returns a 2-dimensional view of each input tensor with zero dimensions. Input tensors with two or more dimensions are returned as-is.

The interface is consistent with PyTorch.

The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.atleast_2d.html.

Parameters

tensors (List[oneflow.Tensor] or oneflow.Tensor) – Tensor or list of tensors to be reshaped

Returns

A Tensor

For example:

>>> import oneflow as flow
>>> x = flow.tensor(0)
>>> x.shape
oneflow.Size([])
>>> flow.atleast_2d(x).shape
oneflow.Size([1, 1])
>>> x = flow.randn(3)
>>> flow.atleast_2d(x).shape
oneflow.Size([1, 3])
>>> x = flow.randn(3, 3)
>>> flow.atleast_2d(x).shape
oneflow.Size([3, 3])