在 Python 中返回复数参数的虚部
要返回复数参数的虚部,请使用 numpy.imag() 方法。该方法返回复数参数的虚部。如果 val 为实数,则输出使用 val 的类型。如果 val 包含复数元素,则返回类型为浮点数。第一个参数 val 是输入数组
步骤
首先,导入所需的库 -
import numpy as np
使用 array() 方法创建数组 -
arr = np.array([36.+5.j , 27.+3.j , 68.+2.j , 23.+7.j])
显示数组 -
print("Our Array...\n",arr)检查维度 -
print("\nDimensions of our Array...\n",arr.ndim)
获取数据类型 -
print("\nDatatype of our Array object...\n",arr.dtype)获取形状 -
print("\nShape of our Array...\n",arr.shape)要在 Python 中返回复数参数的虚部,请使用 numpy.imag() 方法。该方法返回复数参数的虚部。如果 val 为实数,则输出使用 val 的类型。如果 val 包含复数元素,则返回类型为浮点数。第一个参数 val 是输入数组 -
print("\nResult (Imaginary part)...\n",np.imag(arr))示例
import numpy as np
# Create an array using the array() method
arr = np.array([36.+5.j , 27.+3.j , 68.+2.j , 23.+7.j])
# Display the array
print("Our Array...\n",arr)
# Check the Dimensions
print("\nDimensions of our Array...\n",arr.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",arr.dtype)
# Get the Shape
print("\nShape of our Array...\n",arr.shape)
# To return the imaginary part of the complex argument, use the numpy.imag() method in Python
print("\nResult (Imaginary part)...\n",np.imag(arr))输出
Our Array... [36.+5.j 27.+3.j 68.+2.j 23.+7.j] Dimensions of our Array... 1 Datatype of our Array object... complex128 Shape of our Array... (4,) Result (Imaginary part)... [5. 3. 2. 7.]
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP