Compute the inverse Hyperbolic sine of array elements in Python

PythonNumpyServer Side ProgrammingProgramming

The arcsinh is a multivalued function: for each x there are infinitely many numbers z such that sinh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2]. For real-valued input data types, arcsinh always returns real output. For each value that cannot be expressed as a real number or infinity, it returns nan and sets the invalid floating point error flag.

For complex-valued input, arccos is a complex analytical function that has branch cuts [1j, infj] and [- 1j, -infj] and is continuous from the right on the former and from the left on the latter. The inverse hyperbolic sine is also known as asinh or sinh^-1.

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. The 1st parameter, x is input array. The 2nd and 3rd parameters are optional.

The 2nd parameter is an ndarray, 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. The 3rd parameter is the condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value.

Steps

At first, import the required library −

import numpy as np

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))

Displaying our array −

print("Array...\n",arr)

Get the datatype −

print("\nArray datatype...\n",arr.dtype)

Get the dimensions of the Array −

print("\nArray Dimensions...\n",arr.ndim)

Get the number of elements of the Array −

print("\nNumber of elements in the Array...\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))

Example

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))

Output

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]
raja
Updated on 25-Feb-2022 06:35:03

Advertisements