mindspore.ops.atleast_2d

mindspore.ops.atleast_2d(inputs)[source]

Reshapes Tensor in inputs, every Tensor has at least 2 dimension after this operation.

Scalar or 1-D Tensor is converted to 2-D Tensor, tensor with higher dimensions will be returned as it is.

Parameters

inputs (Union[Tensor, list[Tensor]]) – One or more input tensors.

Returns

Tensor or list[Tensor]. If returned a list, every element a in that list satisfies a.ndim >= 2 .

Raises

TypeError – If the inputs is not a tensor or a list of tensors.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore.numpy as np
>>> from mindspore import ops
>>> x1 = np.ones((2, 3))
>>> x2 = np.ones(())
>>> x3 = np.ones(5)
>>> out = ops.atleast_2d([x1, x2, x3])
>>> print(out)
(Tensor(shape=[2, 3], dtype=Float32, value=
[[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00],
[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]), Tensor(shape=[1, 1], dtype=Float32, value=
[[ 1.00000000e+00]]), Tensor(shape=[1, 5], dtype=Float32, value=
[[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]))