當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。