📜  Python| numpy ndarray.real()

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

Python| numpy ndarray.real()

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

示例 #1:
在此示例中,我们可以看到我们使用ndarray.real()方法获取了实数值数组,并且我们还尝试打印这些实数值的 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.real() method
geeks = np.real(gfg)
    
print(geeks, end ='\n\n')
print(np.real(geeks).dtype)
输出:
[ 1.  2.]

'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.real() method
geeks = np.real(gfg)
    
print(geeks, end ='\n\n')
print(np.real(geeks).dtype)
输出:
[ 1.27201965  1.67414923]

float64