mindspore.ops.scalar_to_tensor

View Source On Gitee
mindspore.ops.scalar_to_tensor(input_x, dtype=mstype.float32)[source]

Converts a scalar to a tensor with the specified dtype.

Parameters
  • input_x (Union[bool, int, float]) – The input scalar. Only constant value is allowed.

  • dtype (mindspore.dtype) – The dtype of returned tensor. Only constant value is allowed.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> data = 1
>>> output = mindspore.ops.scalar_to_tensor(data, mindspore.float32)
>>> print(output)
1.0