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


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


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

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

返回:

boolean array containing the result

代码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 begining 
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



相关用法


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