NumPy sinh() Function



The NumPy sinh() function is used to calculate the hyperbolic sine of each element in the input array. It computes the value of sin(x) = (ex - e(-x)) / 2 for each element in the array, where e is Euler's number (approximately 2.71828). This function is commonly used in hyperbolic functions.

  • Domain: The function accepts real-valued input and can handle both positive and negative values. The domain is all real numbers.
  • Range: The output values can be any real number, ranging from negative to positive infinity, as the hyperbolic sine function spans the entire set of real numbers.

Syntax

Following is the syntax of the NumPy sinh() function −

numpy.sinh(x, /, out=None, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])

Parameters

This function accepts the following parameters −

  • x: The input array or scalar. The function computes the hyperbolic sine for each element in the array or scalar.
  • out (optional): A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.
  • where (optional): This condition is broadcast over the input. At locations where the condition is True, the result will be computed. Otherwise, the result will retain its original value.
  • casting (optional): Controls what kind of data casting may occur. Defaults to 'same_kind'.
  • order (optional): Controls the memory layout order of the result. 'C' means C-order, 'F' means Fortran-order, 'A' means 'F' if inputs are all F, 'C' otherwise, 'K' means match the layout of the inputs as closely as possible.
  • dtype (optional): The type of the returned array and of the accumulator in which the elements are processed. The dtype of x is used by default unless dtype is specified.
  • subok (optional): If True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array.

Return Value

This function returns an array where each element is the hyperbolic sine of the corresponding element in the input array x.

Example: Basic Usage of sinh() Function

In the following example, we use the sinh() function to compute the hyperbolic sine of each element in a 1-dimensional array −

import numpy as np

# Creating a 1-dimensional array
arr = np.array([0, 1, 2, 3])

# Applying sinh to each element
result = np.sinh(arr)
print(result)

The output obtained will be −

[ 0.          1.17520119  3.62686041 10.01787493]

Example: Hyperbolic Sine of Negative Values

In this example, we calculate the hyperbolic sine of negative values. The hyperbolic sine function is odd, meaning that sinh(-x) = -sinh(x) −

import numpy as np

# Negative values for the array
arr = np.array([-1, -2, -3])

# Applying sinh to each element
result = np.sinh(arr)
print(result)

This will produce the following result −

[ -1.17520119  -3.62686041 -10.01787493]

Example: Hyperbolic Sine for Scalar Value

In this example, we use the sinh() function to calculate the hyperbolic sine of a scalar value −

import numpy as np

# Scalar value
scalar = 1

# Applying sinh to the scalar
result = np.sinh(scalar)
print(result)

The output obtained is −

1.1752011936438014

Example: Hyperbolic Sine of an Array with Different Shapes

In this example, we calculate the hyperbolic sine of two arrays with different shapes. NumPy will broadcast the arrays to be compatible for element-wise computation −

import numpy as np

# Creating two arrays with different shapes
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])

# Applying sinh to each pair of elements (broadcasting)
result = np.sinh(arr1 + arr2)
print(result)

This will produce the following result −

[  74.20321058  548.31612327 4051.54190208]
numpy_trigonometric_functions.htm
Advertisements