mindspore.ops.atleast_1d

查看源文件
mindspore.ops.atleast_1d(inputs)[源代码]

当输入中的tensor为零维时,返回它的一维tensor。其他维度的tensor,直接返回原tensor。

参数:
  • inputs (Union[Tensor, list[Tensor]]) - 输入tensor或tensor列表。

返回:

tensor或tensor列表。

支持平台:

Ascend GPU CPU

样例:

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