Python numpy.iscomplexobj()

Python numpy.iscomplexobj()

numpy.iscomplexobj(array) :这个逻辑函数帮助检查一个数组或复数数组的复数类型。即使虚数部分等于零,也被认为是复数对象。

参数 :

array : [array_like]输入数组或对象的元素,我们需要测试。

返回 :

如果输入数组有一个复数元素,则为真,否则为假

代码 1 :

# Python program explaining
# iscomplexobj() function
import numpy as np
 
in_array = [1, 3, 5, 4]
print ("Input array : ", in_array)
 
output_value = np.iscomplexobj(in_array)
print ("\nIs complex : ", output_value)

输出 :

Input array :  [1, 3, 5, 4]

Is complex :  False

代码 2 :

# Python Program illustrating
# numpy.iscomplexobj() method
import numpy as geek
   
# Returns True/False value for each element
a = geek.arange(20).reshape(5, 4)
print("Is complex : \n", geek.iscomplexobj(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 complex : ", geek.iscomplexobj(b))
  
  
b = [[1j],
     [3]]
print("\nIs complex : \n", geek.iscomplexobj(b))

输出 :

Is complex : 
 False

 class 'complex'

Is complex :  False

Is complex : 
 True

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程