atleast_3d

paddle. atleast_3d ( *inputs, name=None ) [source]

Convert inputs to tensors and return the view with at least 3-dimension. Three or high-dimensional inputs are preserved.

Parameters
  • inputs (Tensor|list(Tensor)) – One or more tensors. The data type is float16, float32, float64, int16, int32, int64, int8, uint8, complex64, complex128, bfloat16 or bool.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

One Tensor, if there is only one input. List of Tensors, if there are more than one inputs.

Examples

>>> import paddle

>>> # one input
>>> x = paddle.to_tensor(123, dtype='int32')
>>> out = paddle.atleast_3d(x)
>>> print(out)
Tensor(shape=[1, 1, 1], dtype=int32, place=Place(cpu), stop_gradient=True,
[[[123]]])

>>> # more than one inputs
>>> x = paddle.to_tensor(123, dtype='int32')
>>> y = paddle.to_tensor([1.23], dtype='float32')
>>> out = paddle.atleast_3d(x, y)
>>> print(out)
[Tensor(shape=[1, 1, 1], dtype=int32, place=Place(cpu), stop_gradient=True,
[[[123]]]), Tensor(shape=[1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[1.23000002]]])]

>>> # more than 3-D input
>>> x = paddle.to_tensor(123, dtype='int32')
>>> y = paddle.to_tensor([[[[1.23]]]], dtype='float32')
>>> out = paddle.atleast_3d(x, y)
>>> print(out)
[Tensor(shape=[1, 1, 1], dtype=int32, place=Place(cpu), stop_gradient=True,
[[[123]]]), Tensor(shape=[1, 1, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[[1.23000002]]]])]