Open In App

numpy.iscomplex() in Python

Last Updated : 08 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The numpy.iscomplex() function tests element-wise whether it is a complex number or not(not infinity or not Not a Number) and returns the result as a boolean array. Syntax : 

numpy.iscomplex(array)

Parameters : 

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

Return : 

boolean array containing the result

Code 1 : 

Python
# 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")

Output : 

Is Complex :  [ True False] 

Is Complex :  [ True False] 

Code 2 : 

Python
# 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 beginning
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))

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]]

Note : These codes won't run on online IDE's. So please, run them on your systems to explore the working. 


Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy