mindspore.ops.ScalarToTensor

class mindspore.ops.ScalarToTensor[source]

Converts a scalar to a Tensor, and converts the data type to the specified type.

Refer to mindspore.ops.scalar_to_tensor() for more details.

Inputs:
  • input_x (Union[int, float]) - The input is a scalar. Only constant value is allowed.

  • dtype (mindspore.dtype) - The target data type. Default: mindspore.float32. Only constant value is allowed.

Outputs:

Tensor. 0-D Tensor and the content is the input.

Supported Platforms:

Ascend GPU CPU

Examples

>>> op = ops.ScalarToTensor()
>>> data = 1
>>> output = op(data, mindspore.float32)
>>> print(output)
1.0