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