在 Python 中计算数组元素的双曲正弦


要计算数组元素的双曲正弦,请在 Python NumPy 中使用 numpy.sinh() 方法。此方法等效于 1/2 * (np.exp(x) - np.exp(-x)) 或 -1j * np.sin(1j*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.sinh(arr))

示例

Open Compiler
import numpy as np # To compute the Hyperbolic sine of the array elements, use the numpy.sinh() method in Python Numpy # The method is equivalent to 1/2 * (np.exp(x) - np.exp(-x)) or -1j * np.sin(1j*x). print("Get the Trigonometric Hyperbolic sine of the 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 hyperbolic sines of the array elements, use the numpy.sinh() method in Python Numpy print("\nResult...",np.sinh(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 Hyperbolic sine of the 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.00000000e+00+0.0000000e+00j 5.34323729e+12+0.0000000e+00j
1.74671355e+19+0.0000000e+00j 5.71003695e+25+0.0000000e+00j
6.10201647e+38+0.0000000e+00j 7.44692100e+77+0.0000000e+00j
0.00000000e+00+1.0000000e+00j -0.00000000e+00+1.2246468e-16j]

更新于:2022年2月25日

165 次浏览

启动您的 职业生涯

完成课程获得认证

开始学习
广告