mindspore.mint.real

View Source On Gitee
mindspore.mint.real(input) Tensor[source]

Return a new tensor containing the real values of the input tensor. If input is real, it is returned unchanged. The returned tensor and input tensor share the same underlying storage.

Note

Only support Pynative mode.

Parameters

input (Tensor) – The input tensor.

Returns

Tensor, the shape is same as input. The data type is float32 if input is complex64, float64 when input is complex128. Otherwise, the data type is the same as input.

Raises

ValueError – If input tensor has no storage info.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> from mindspore import Tensor, mint, ops, context
>>> context.set_context(mode=context.PYNATIVE_MODE, device_target="Ascend")
>>> real = Tensor([1.1, 2.1, 3.1], mindspore.float32)
>>> imag = Tensor([4.1, 5.1, 6.1], mindspore.float32)
>>> x = ops.Complex()(real, imag)
>>> output = mint.real(x)
>>> print(output)
[1.1 2.1 3.1]
>>> print(output.dtype)
Float32
>>> real = Tensor([1.1, 2.1, 3.1], mindspore.float64)
>>> imag = Tensor([4.1, 5.1, 6.1], mindspore.float64)
>>> x = ops.Complex()(real, imag)
>>> output = mint.real(x)
>>> print(output)
[1.1 2.1 3.1]
>>> print(output.dtype)
Float64