返回 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]
廣告