numpy.iscomplex() in Python

About :
numpy.iscomplex(array) : Test element-wise whether it is a complex number or not(not infinity or not Not a Number) and return the result as a boolean array.
Parameters :

array : [array_like] Input array whose element we want to test

Return :

boolean array containing the result

Code 1 :



filter_none

edit
close

play_arrow

link
brightness_4
code

# Python Program illustrating
# numpy.iscomplex() method
   
import numpy as geek 
  
print("Is Complex : ", geek.iscomplex([1+1j, 1+0j]), "\n")
  
print("Is Complex : ", geek.iscomplex([0+1j, 0]), "\n")

chevron_right


Output :

Is Complex :  [ True False] 

Is Complex :  [ True False] 

Code 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python Program illustrating
# numpy.iscomplex() method
    
import numpy as geek 
   
# Returns True/False value for each element 
a = geek.arange(20).reshape(5, 4)
print("Is complex : \n", geek.iscomplex(a))
   
# Returns True/False value as ans 
# because we have mentioned dtpe in the begining
b = geek.arange(20).reshape(5, 4).dtype = complex
                 
print("\n",b)
print("\nIs complex : ", geek.iscomplex(b))
  
  
b = [[1j], 
     [3]]
print("\nIs complex : \n", geek.iscomplex(b))

chevron_right


Output :

Is complex : 
 [[False False False False]
 [False False False False]
 [False False False False]
 [False False False False]
 [False False False False]]

Is complex :  False

Is complex : 
 [[ True]
 [False]]

References :
https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.isfinite.html

Note :
These codes won’t run on online-ID. Please run them on your systems to explore the working
.
This article is contributed by Mohit Gupta_OMG 😀. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up

Recommended Posts: