Python中的 numpy.iscomplex()
numpy.iscomplex()函数逐元素测试它是否是复数(不是无穷大或不是不是数字),并将结果作为布尔数组返回。句法 :
numpy.iscomplex(array)
参数 :
array : [array_like] Input array whose element we want to test
返回 :
boolean array containing the result
代码 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")
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))
输出 :
Is Complex : [ True False]
Is Complex : [ True False]
代码 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))
输出 :
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]]
参考: https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.isfinite.html
注意:这些代码不会在在线 IDE 上运行。因此,请在您的系统上运行它们以探索其工作原理。