Compute complex conjugate of an/a array/tensor. Supports Ndim inputs with last dim equal to 2 (real/imaginary channels) Args: x: Input array/tensor with 2 channels in the last dimension representing real and imaginary parts. Returns: Complex conjugate of x Example
(x: NdarrayOrTensor)
| 206 | |
| 207 | |
| 208 | def complex_conj(x: NdarrayOrTensor) -> NdarrayOrTensor: |
| 209 | """ |
| 210 | Compute complex conjugate of an/a array/tensor. Supports Ndim inputs with last dim equal to 2 (real/imaginary channels) |
| 211 | |
| 212 | Args: |
| 213 | x: Input array/tensor with 2 channels in the last dimension representing real and imaginary parts. |
| 214 | |
| 215 | Returns: |
| 216 | Complex conjugate of x |
| 217 | |
| 218 | Example: |
| 219 | .. code-block:: python |
| 220 | |
| 221 | import numpy as np |
| 222 | x = np.array([[1,2],[3,4]]) |
| 223 | # the following line prints array([[ 1, -2], [ 3, -4]]) |
| 224 | print(complex_conj(x)) |
| 225 | """ |
| 226 | if x.shape[-1] != 2: |
| 227 | raise ValueError(f"last dim must be 2, but x.shape[-1] is {x.shape[-1]}.") |
| 228 | |
| 229 | if isinstance(x, Tensor): |
| 230 | return complex_conj_t(x) |
| 231 | else: |
| 232 | np_conj: np.ndarray = np.stack((x[..., 0], -x[..., 1]), axis=-1) |
| 233 | return np_conj |
searching dependent graphs…