Python numpy.isreal()
Python numpy.isreal(array) :测试元素是否为实数(非无穷大或非非数字),并将结果作为布尔数组返回。
参数 :
array : [array_like] 输入数组,我们要测试其元素。
返回 :
boolean array containing the result
代码 1 :
# Python Program illustrating
# numpy.isreal() method
import numpy as geek
print("Is Real : ", geek.isreal([1+1j, 0j]), "\n")
print("Is Real : ", geek.isreal([1, 0]), "\n")
输出 :
Is Real : [False True]
Is Real : [ True True]
代码 2 :
# Python Program illustrating
# numpy.isreal() method
import numpy as geek
# Returns True/False value for each element
a = geek.arange(20).reshape(5, 4)
print("Is Real : \n", geek.isreal(a), "\n")
# Returns True/False value as ans
# because we have mentioned dtype in the beginning
a = geek.arange(20).reshape(5, 4).dtype = float
print("\nIs Real : ", geek.isreal(a))
输出 :
Is Real :
[[ True True True True]
[ True True True True]
[ True True True True]
[ True True True True]
[ True True True True]]
Is Real : True