r"""Returns the real part of a complex (or real) tensor. Given a tensor `input`, this operation returns a tensor of type `float` that is the real part of each element in `input` considered as a complex number. For example: ```python x = tf.constant([-2.25 + 4.75j, 3.25 + 5.75j]) tf.ma
(input, name=None)
| 509 | @deprecation.deprecated_endpoints("real") |
| 510 | @dispatch.add_dispatch_support |
| 511 | def real(input, name=None): |
| 512 | r"""Returns the real part of a complex (or real) tensor. |
| 513 | |
| 514 | Given a tensor `input`, this operation returns a tensor of type `float` that |
| 515 | is the real part of each element in `input` considered as a complex number. |
| 516 | |
| 517 | For example: |
| 518 | |
| 519 | ```python |
| 520 | x = tf.constant([-2.25 + 4.75j, 3.25 + 5.75j]) |
| 521 | tf.math.real(x) # [-2.25, 3.25] |
| 522 | ``` |
| 523 | |
| 524 | If `input` is already real, it is returned unchanged. |
| 525 | |
| 526 | Args: |
| 527 | input: A `Tensor`. Must have numeric type. |
| 528 | name: A name for the operation (optional). |
| 529 | |
| 530 | Returns: |
| 531 | A `Tensor` of type `float32` or `float64`. |
| 532 | """ |
| 533 | with ops.name_scope(name, "Real", [input]) as name: |
| 534 | input = ops.convert_to_tensor(input, name="input") |
| 535 | if input.dtype.is_complex: |
| 536 | real_dtype = input.dtype.real_dtype |
| 537 | return gen_math_ops.real(input, Tout=real_dtype, name=name) |
| 538 | else: |
| 539 | return input |
| 540 | |
| 541 | |
| 542 | @tf_export("math.imag", v1=["math.imag", "imag"]) |