mindspore.ops.cast
- mindspore.ops.cast(input, dtype)[source]
Returns a tensor with the new specified data type.
Warning
This interface is deprecated and will be removed after version 2.9.0.
Note
When converting complex numbers to boolean type, the imaginary part of the complex number is not taken into account. As long as the real part is non-zero, it returns
True; otherwise, it returnsFalse.- Parameters:
input (Union[Tensor, Number]) – The input tensor or number.
dtype (dtype.Number) – The dtype after conversion. Only constant value is allowed.
- Returns:
Tensor
- Supported Platforms:
AscendGPUCPU
Examples
>>> import mindspore >>> input = mindspore.tensor([1, 2, 3], mindspore.int32) >>> dtype = mindspore.float64 >>> output = mindspore.ops.cast(input, dtype) >>> print(output.dtype) Float64 >>> print(output) [1. 2. 3.]