在 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