mindspore.ops.scalar_to_tensor

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[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.

Returns

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

Raises

TypeError – If input_x is neither int nor float.

Supported Platforms:

Ascend GPU CPU

Examples

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