在Python中返回复数参数的弧度角
要返回复数参数的角度,请在Python中使用numpy.angle()方法。该方法返回复数平面上从正实轴逆时针方向的角度,范围为(-pi, pi],数据类型为numpy.float64。第一个参数z是复数或一系列复数。第二个参数deg如果为True,则以度为单位返回角度;如果为False(默认值),则以弧度为单位返回角度。
步骤
首先,导入所需的库 –
import numpy as np
使用array()方法创建数组-
arr = np.array([1.0, 1.0j, 1+1j])
显示数组 –
print("Array...\n", arr)
获取数组的类型 –
print("\nOur Array type...\n", arr.dtype)
获取数组的尺寸 –
print("\nOur Array Dimension...\n",arr.ndim)
获取数组的形状 −
print("\nOur Array Shape...\n",arr.shape)
使用Python Numpy中的numpy.angle()方法返回复数参数的角度。该方法返回复平面上与正实轴的逆时针角度在(-pi,pi]范围内的角度,数据类型为numpy.float64 –
print("\nResult (radians)...\n", np.angle(arr))
示例
import numpy as np
# Create an array using the array() method
arr = np.array([1.0, 1.0j, 1+1j])
# Display the array
print("Array...\n", arr)
# Get the type of the array
print("\nOur Array type...\n", arr.dtype)
# Get the dimensions of the Array
print("\nOur Array Dimension...\n",arr.ndim)
# Get the shape of the Array
print("\nOur Array Shape...\n",arr.shape)
# To return the angle of the complex argument, use the numpy.angle() method in Python Numpy
# The method returns the counterclockwise angle from the positive real axis on the complex plane in the range (-pi, pi], with dtype as numpy.float64.
print("\nResult (radians)...\n", np.angle(arr))
输出
Array...
[1.+0.j 0.+1.j 1.+1.j]
Our Array type...
complex128
Our Array Dimension...
1
Our Array Shape...
(3,)
Result (radians)...
[0. 1.57079633 0.78539816]