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, and converts the data type to the specified type.

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

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

Returns

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

Raises

TypeError – If input_x is neither bool nor int nor float.

Supported Platforms:

Ascend GPU CPU

Examples

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