mindspore.ops.atleast_2d

View Source On Gitee
mindspore.ops.atleast_2d(inputs)[source]

Returns a 2-dimensional tensor of each tensor, while tensors with two or more dimensions remain unchanged.

Parameters

inputs (Union[Tensor, list[Tensor]]) – The input tensor or list of tensors.

Returns

Tensor or list of tensors.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> # case 1: Input is a zero-dimensional tensor.
>>> x = mindspore.tensor(1)
>>> mindspore.ops.atleast_2d(x)
Tensor(shape=[1, 1], dtype=Int64, value= [[1]])
>>>
>>> # case 2: Input is a 2-dimensional tensor.
>>> y = mindspore.tensor([[0, 1], [2, 3]])
>>> mindspore.ops.atleast_2d(y)
Tensor(shape=[2, 2], dtype=Int64, value=
[[0, 1],
 [2, 3]])
>>>
>>> # case 3: Input is a list containing tensors of various dimensions.
>>> mindspore.ops.atleast_2d([x, y])
(Tensor(shape=[1, 1], dtype=Int64, value=
 [[1]]),
 Tensor(shape=[2, 2], dtype=Int64, value=
 [[0, 1],
  [2, 3]]))