view_as_complex functionkeras.ops.view_as_complex(x)
Converts a real tensor with shape (..., 2) to a complex tensor,
where the last dimension represents the real and imaginary components
of a complex tensor.
Arguments
Returns
x.shape[__:-1].Example
```python
>>> import numpy as np
>>> from keras import ops
>>> real_imag = np.array([[1.0, 2.0], [3.0, 4.0]])
>>> complex_tensor = ops.view_as_complex(real_imag)
>>> complex_tensor
array([1.+2.j, 3.+4.j])
----
<span style="float:right;">[[source]](https://github.com/keras-team/keras/tree/v3.13.2/keras/src/ops/math.py#L1105)</span>
### `view_as_real` function
```python
keras.ops.view_as_real(x)
Converts a complex tensor to a real tensor with shape (..., 2),
where the last dimension represents the real and imaginary components.
Arguments
Returns
A real tensor where the last dimension contains the real and imaginary parts.
Example
```python
>>> import numpy as np
>>> from keras import ops
>>> complex_tensor = np.array([1 + 2j, 3 + 4j])
>>> real = ops.view_as_real(complex_tensor)
>>> real
array([[1., 2.],
[3., 4.]])
```