Return the real part of the complex argument. Parameters ---------- val : array_like Input array. Returns ------- out : ndarray or scalar The real component of the complex argument. If `val` is real, the type of `val` is used for the output. If
(val)
| 119 | |
| 120 | @array_function_dispatch(_real_dispatcher) |
| 121 | def real(val): |
| 122 | """ |
| 123 | Return the real part of the complex argument. |
| 124 | |
| 125 | Parameters |
| 126 | ---------- |
| 127 | val : array_like |
| 128 | Input array. |
| 129 | |
| 130 | Returns |
| 131 | ------- |
| 132 | out : ndarray or scalar |
| 133 | The real component of the complex argument. If `val` is real, the type |
| 134 | of `val` is used for the output. If `val` has complex elements, the |
| 135 | returned type is float. |
| 136 | |
| 137 | See Also |
| 138 | -------- |
| 139 | real_if_close, imag, angle |
| 140 | |
| 141 | Examples |
| 142 | -------- |
| 143 | >>> a = np.array([1+2j, 3+4j, 5+6j]) |
| 144 | >>> a.real |
| 145 | array([1., 3., 5.]) |
| 146 | >>> a.real = 9 |
| 147 | >>> a |
| 148 | array([9.+2.j, 9.+4.j, 9.+6.j]) |
| 149 | >>> a.real = np.array([9, 8, 7]) |
| 150 | >>> a |
| 151 | array([9.+2.j, 8.+4.j, 7.+6.j]) |
| 152 | >>> np.real(1 + 1j) |
| 153 | 1.0 |
| 154 | |
| 155 | """ |
| 156 | try: |
| 157 | return val.real |
| 158 | except AttributeError: |
| 159 | return asanyarray(val).real |
| 160 | |
| 161 | |
| 162 | def _imag_dispatcher(val): |
no test coverage detected