mindspore.ops.ScalarToTensor

class mindspore.ops.ScalarToTensor(*args, **kwargs)[source]

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

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.

Raises

TypeError – If input_x is neither int nor float.

Supported Platforms:

Ascend GPU CPU

Examples

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