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


Python numpy.isrealobj()用法及代碼示例

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