使用scimath在Python中计算反正弦
要使用scimath计算反正弦,在Python中使用numpy.emath.arcsin()方法。返回x的“主值”反正弦。对于满足abs(x)<=1的实数x,这是一个位于闭区间[-π/2,π/2]的实数。否则,返回复数主值。
该方法返回x值的反正弦。如果x是标量,则out也是标量,否则返回一个数组对象。第一个参数是需要计算反正弦的数值。
步骤
首先,导入所需的库 –
import numpy as np
使用array()方法创建一个numpy数组 −
arr = np.array([0, 1, -1, 2])
显示数组 −
print("Array...\n", arr)
获取数组的类型 –
print("\nOur Array type...\n", arr.dtype)
获取数组的维度 –
print("\nOur Array Dimensions...\n",arr.ndim)
使用scimath计算反正弦,在Python中使用numpy.emath.arcsin()方法 –
print("\nResult...",np.emath.arcsin(arr))
示例
import numpy as np
# Create a numpy array using the array() method
arr = np.array([0, 1, -1, 2])
# 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 sine with scimath, use the numpy.emath.arcsin() method in Python
print("\nResult...",np.emath.arcsin(arr))
输出
Array...
[ 0 1 -1 2]
Our Array type...
int64
Our Array Dimensions...
1
Number of elements...
4
Result... [ 0. +0.j 1.57079633+0.j -1.57079633+0.j
1.57079633+1.3169579j]