📜  Python中的 numpy.isreal()

📅  最后修改于: 2022-05-13 01:55:14.111000             🧑  作者: Mango

Python中的 numpy.isreal()

numpy.isreal(array) :按元素测试它是否是实数(不是无穷大或不是不是数字)并将结果作为布尔数组返回。
参数 :

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

返回 :

boolean array containing the result

代码 1:

Python
# 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")


Python
# 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 dtype in the beginning
a = geek.arange(20).reshape(5, 4).dtype = float
print("\nIs Real : ", geek.isreal(a))


输出 :

Is Real :  [False  True] 

Is Real :  [ True  True] 

代码 2:

Python

# 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 dtype 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
笔记 :
这些代码不会在在线 IDE 上运行。因此,请在您的系统上运行它们以探索其工作原理。