在 Python 中使用 scimath 計算反餘弦
若想用 scimath 計算反餘弦,在 Python 中使用 numpy.emath.arccos() 方法。返回 x 的反餘弦的“主值”。對於實數 abs(x) <= 1,它是一個介於閉區間 [0,π] 內的實數。否則,返回復主值。
該方法返回 x 值的反餘弦值。如果 x 是標量,那麼 out 也是標量,否則返回一個數組物件。第 1 個引數是需要求反餘弦的值。
步驟
首先,匯入所需的庫 −
import numpy as np
使用 array() 方法建立 numpy 陣列 −
arr = np.array([1, -1, 2, 0])
顯示陣列 −
print("Array...\n", arr)獲取陣列的型別 −
print("\nOur Array type...\n", arr.dtype)
獲取陣列的維度 −
print("\nOur Array Dimension...\n",arr.ndim)若想用 scimath 計算反餘弦,在 Python 中使用 numpy.emath.arccos() 方法 −
print("\nResult...",np.emath.arccos(arr))
示例
import numpy as np
# Create a numpy array using the array() method
arr = np.array([1, -1, 2, 0])
# 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 Dimensions...\n",arr.ndim)
# Get the number of elements in the Array
print("\nNumber of elements...\n", arr.size)
# To compute the inverse cosine with scimath, use the numpy.emath.arccos() method in Python
print("\nResult...",np.emath.arccos(arr))輸出
Array... [ 1 -1 2 0] Our Array type... int64 Our Array Dimensions... 1 Number of elements... 4 Result... [0. -0.j 3.14159265-0.j 0. -1.3169579j 1.57079633-0.j ]
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP