numpy.isrealobj(array):此逻辑函数有助于检查数组是否没有复杂类型或数组是否具有复杂数字。即使虚部等于零,也不会将其视为实物。
参数:
array :[array_like]Input array or object whose elements, we need to test.
返回:
True, if the input array hasn't any complex element; otherwise False
代码1:
# Python program explaining
# isrealobj() function
import numpy as np
in_array = [1, 3, 5, 4]
print ("Input array:", in_array)
output_value = np.isrealobj(in_array)
print ("\nIs real:", output_value)
输出:
Input array: [1, 3, 5, 4] Is real: True
代码2:
# Python Program illustrating
# numpy.isrealobj() method
import numpy as geek
# Returns True/False value for each element
a = geek.arange(20).reshape(5, 4)
print("Is real:", geek.isrealobj(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 real:", geek.isrealobj(b))
b = [[1j],
[3]]
print("\nIs real:", geek.isrealobj(b))
输出:
Is real: True class 'complex' Is real: True Is real: False
参考文献:
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.isrealobj.html#numpy.isrealobj
。
相关用法
注:本文由纯净天空筛选整理自Mohit Gupta_OMG 大神的英文原创作品 numpy.isrealobj() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。