📜  Python| numpy ndarray.imag()

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

Python| numpy ndarray.imag()

借助Numpy ndarray.imag()方法,我们只需使用ndarray.imag()方法就可以找到虚数表达式中的虚数值。请记住,虚数的结果数据类型是'float64'

示例 #1:
在这个例子中,我们可以看到我们使用ndarray.imag()方法获取了虚值数组,并且我们还尝试打印这些 imag 值的 dtype。

# import the important module in python
import numpy as np
          
# make an array with numpy
gfg = np.array([1 + 2j, 2 + 3j])
          
# applying ndarray.imag() method
geeks = np.imag(gfg)
    
print(geeks, end ='\n\n')
print(np.imag(geeks).dtype)
输出:
[ 2.  3.]

float64

示例 #2:

# import the important module in python
import numpy as np
          
# make an array with numpy
gfg = np.array([1 + 2j, 2 + 3j])
gfg = np.sqrt(gfg)
          
# applying ndarray.imag() method
geeks = np.imag(gfg)
    
print(geeks, end ='\n\n')
print(np.imag(geeks).dtype)
输出:
[ 0.78615138  0.89597748]

float64