当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy.isreal()用法及代码示例


numpy.isreal(array):逐一测试是否为实数(不是无穷大还是不是数字),然后将结果作为布尔数组返回。
参数:

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

返回:

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

参考文献:
https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.isreal.html#numpy.isreal



相关用法


注:本文由纯净天空筛选整理自 numpy.isreal() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。