返回 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...\n", np.angle(arr))示例
import numpy as np
# Create an array using the array() methodd
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...\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... [0. 1.57079633 0.78539816]
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP