mindspore.ops.scalar_to_array

mindspore.ops.scalar_to_array(input_x)[source]

Converts a scalar to a Tensor.

Parameters

input_x (Union[int, float]) – The input is a scalar. 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

>>> input_x = 1.0
>>> print(type(input_x))
<class 'float'>
>>> output = ops.scalar_to_array(input_x)
>>> print(type(output))
<class 'mindspore.common.tensor.Tensor'>
>>> print(output)
1.0