Return the imaginary part of the complex argument. Parameters ---------- val : array_like Input array. Returns ------- out : ndarray or scalar The imaginary component of the complex argument. If `val` is real, the type of `val` is used for the o
(val)
| 165 | |
| 166 | @array_function_dispatch(_imag_dispatcher) |
| 167 | def imag(val): |
| 168 | """ |
| 169 | Return the imaginary part of the complex argument. |
| 170 | |
| 171 | Parameters |
| 172 | ---------- |
| 173 | val : array_like |
| 174 | Input array. |
| 175 | |
| 176 | Returns |
| 177 | ------- |
| 178 | out : ndarray or scalar |
| 179 | The imaginary component of the complex argument. If `val` is real, |
| 180 | the type of `val` is used for the output. If `val` has complex |
| 181 | elements, the returned type is float. |
| 182 | |
| 183 | See Also |
| 184 | -------- |
| 185 | real, angle, real_if_close |
| 186 | |
| 187 | Examples |
| 188 | -------- |
| 189 | >>> a = np.array([1+2j, 3+4j, 5+6j]) |
| 190 | >>> a.imag |
| 191 | array([2., 4., 6.]) |
| 192 | >>> a.imag = np.array([8, 10, 12]) |
| 193 | >>> a |
| 194 | array([1. +8.j, 3.+10.j, 5.+12.j]) |
| 195 | >>> np.imag(1 + 1j) |
| 196 | 1.0 |
| 197 | |
| 198 | """ |
| 199 | try: |
| 200 | return val.imag |
| 201 | except AttributeError: |
| 202 | return asanyarray(val).imag |
| 203 | |
| 204 | |
| 205 | def _is_type_dispatcher(x): |
no test coverage detected