Check for a complex type or an array of complex numbers. The type of the input is checked, not the value. Even if the input has an imaginary part equal to zero, `iscomplexobj` evaluates to True. Parameters ---------- x : any The input can be of any type and shape.
(x)
| 301 | |
| 302 | @array_function_dispatch(_is_type_dispatcher) |
| 303 | def iscomplexobj(x): |
| 304 | """ |
| 305 | Check for a complex type or an array of complex numbers. |
| 306 | |
| 307 | The type of the input is checked, not the value. Even if the input |
| 308 | has an imaginary part equal to zero, `iscomplexobj` evaluates to True. |
| 309 | |
| 310 | Parameters |
| 311 | ---------- |
| 312 | x : any |
| 313 | The input can be of any type and shape. |
| 314 | |
| 315 | Returns |
| 316 | ------- |
| 317 | iscomplexobj : bool |
| 318 | The return value, True if `x` is of a complex type or has at least |
| 319 | one complex element. |
| 320 | |
| 321 | See Also |
| 322 | -------- |
| 323 | isrealobj, iscomplex |
| 324 | |
| 325 | Examples |
| 326 | -------- |
| 327 | >>> np.iscomplexobj(1) |
| 328 | False |
| 329 | >>> np.iscomplexobj(1+0j) |
| 330 | True |
| 331 | >>> np.iscomplexobj([3, 1+0j, True]) |
| 332 | True |
| 333 | |
| 334 | """ |
| 335 | try: |
| 336 | dtype = x.dtype |
| 337 | type_ = dtype.type |
| 338 | except AttributeError: |
| 339 | type_ = asarray(x).dtype.type |
| 340 | return issubclass(type_, _nx.complexfloating) |
| 341 | |
| 342 | |
| 343 | @array_function_dispatch(_is_type_dispatcher) |