在 Python 中以弧度返回复数参数的角度
pythonnumpyserver side programmingprogramming更新于 2024/5/7 21:00:17
要返回复数参数的角度,请使用 Python 中的 numpy.angle() 方法。该方法返回在复平面上与正实轴逆时针的角度,范围在 (-pi,pi] 内,dtype 为 numpy.float64。第一个参数 z,复数或复数序列。第二个参数 deg,如果为 True,则返回以度为单位的角度,如果为 False(默认),则返回以弧度为单位的角度。
步骤
首先,导入所需的库 −
import numpy as np
使用 array() 方法创建数组 −
arr = np.array([1.0, 1.0j, 1+1j])
显示数组 −
print("数组...\n", arr)
获取数组的类型 −
print("\n我们的数组类型...\n", arr.dtype)
获取数组的维度 −
print("\n我们的数组维度...\n",arr.ndim)
Get the shape of the Array −
print("\n我们的数组形状...\n",arr.shape)
要返回复数参数的角度,请使用 Python Numpy 中的 numpy.angle() 方法。该方法返回复平面上正实轴的逆时针角度,范围为 (-pi, pi],dtype 为 numpy.float64 −
print("\nResult (radians)...\n", np.angle(arr))
示例
import numpy as np
# 使用 array() 方法创建数组
arr = np.array([1.0, 1.0j, 1+1j])
# 显示数组
print("数组...\n", arr)
# 获取数组的类型
print("\n我们的数组类型...\n", arr.dtype)
# Get the dimensions of the Array
print("\n我们的数组维度...\n",arr.ndim)
# Get the shape of the Array
print("\n我们的数组形状...\n",arr.shape)
# 要返回复数参数的角度,请使用 Python Numpy 中的 numpy.angle() 方法
# 该方法返回复平面上正实轴的逆时针角度,范围在 (-pi, pi] 内,dtype 为 numpy.float64。
print("\nResult (radians)...\n", np.angle(arr))
输出
数组... [1.+0.j 0.+1.j 1.+1.j] 我们的数组类型... complex128 我们的数组维度... 1 我们数组的形状... (3,) Result (radians)... [0. 1.57079633 0.78539816]
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

