在 Python 中计算数组元素的反双曲正弦
arcsinh 是一个多值函数:对于每个 x,都有无限多个数字 z 使得 sinh(z) = x。惯例是返回虚部位于 [-pi/2, pi/2] 之间的 z。对于实值输入数据类型,arcsinh 始终返回实数输出。对于不能表示为实数或无穷大的每个值,它返回 nan 并设置无效浮点错误标志。
对于复数输入,arccos 是一个具有分支切割 [1j, infj] 和 [-1j, -infj] 的复解析函数,并且在前者上从右连续,在后者上从左连续。反双曲正弦也称为 asinh 或 sinh^-1。
要计算数组元素的反双曲正弦,请在 Python Numpy 中使用 numpy.arcsinh() 方法。该方法返回与 x 形状相同的数组。如果 x 是标量,则这是一个标量。第一个参数 x 是输入数组。第二个和第三个参数是可选的。
第二个参数是 ndarray,结果存储到其中的位置。如果提供,它必须具有输入广播到的形状。如果不提供或为 None,则返回一个新分配的数组。第三个参数是条件在输入上广播。在条件为 True 的位置,out 数组将设置为 ufunc 结果。在其他地方,out 数组将保留其原始值。
步骤
首先,导入所需的库:
import numpy as np
使用 Numpy 中的 array() 方法创建一个数组:
arr = np.array((0., 30., 45., 60., 90., 180., np.pi*1j/2, np.pi*1j))
显示我们的数组:
print("Array...\n",arr)
获取数据类型:
print("\nArray datatype...\n",arr.dtype)
获取数组的维度:
print("\nArray Dimensions...\n",arr.ndim)
获取数组的元素个数:
print("\nNumber of elements in the Array...\n",arr.size)
要查找数组元素的反双曲正弦,请在 Python Numpy 中使用 numpy.sinh() 方法:
print("\nResult...",np.arcsinh(arr))
示例
import numpy as np # To compute the inverse Hyperbolic sine of array elements, use the numpy.arcsinh() method in Python Numpy # The method returns the array of the same shape as x. This is a scalar if x is a scalar. print("Get the Trigonometric inverse Hyperbolic sine of array elements...") # Create an array using the array() method in Numpy arr = np.array((0., 30., 45., 60., 90., 180., np.pi*1j/2, np.pi*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 Dimensions...\n",arr.ndim) # Get the number of elements in the Array print("\nNumber of elements...\n", arr.size) # To find the inverse hyperbolic sines of the array elements, use the numpy.sinh() method in Python Numpy print("\nResult...",np.arcsinh(arr))
Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.
输出
Get the Trigonometric inverse Hyperbolic sine of array elements... Array... [ 0.+0.j 30.+0.j 45.+0.j 60.+0.j 90.+0.j 180.+0.j 0.+1.57079633j 0.+3.14159265j] Our Array type... complex128 Our Array Dimensions... 1 Number of elements... 8 Result... [0. +0.j 4.09462222+0.j 4.4999331 +0.j 4.78756118+0.j 5.19298771+0.j 5.88611175+0.j 1.02322748+1.57079633j 1.81152627+1.57079633j]