Python numpy.iscomplex()
Python numpy.iscomplex()函数按元素测试它是否是复数(不是无穷大或不是数字),并将结果作为布尔数组返回。
语法 :
numpy.iscomplex(array)
参数 :
array : [array_like] 输入数组,我们要测试其元素。
返回 :
包含结果的布尔数组
示例 1 :
# 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")
输出 :
Is Complex : [ True False]
Is Complex : [ True False]
示例 2 :
# 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))
输出 :
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]]