Shortcuts

torch.atleast_2d

torch.atleast_2d(*tensors)[source]

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

Parameters

input (Tensor or list of Tensors) –

Returns

output (Tensor or tuple of Tensors)

Example:

>>> x = torch.tensor(1.)
>>> x
tensor(1.)
>>> torch.atleast_2d(x)
tensor([[1.]])
>>> x = torch.randn(2,2)
>>> x
tensor([[2.2086, 2.5165],
        [0.1757, 0.5194]])
>>> torch.atleast_2d(x)
tensor([[2.2086, 2.5165],
        [0.1757, 0.5194]])
>>> x = torch.tensor(0.5)
>>> y = torch.tensor(1.)
>>> torch.atleast_2d((x,y))
(tensor([[0.5000]]), tensor([[1.]]))

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources