nums.numpy.tanh

nums.numpy.tanh(x, out=None, where=True, **kwargs)[source]

Compute hyperbolic tangent element-wise.

This docstring was copied from numpy.tanh.

Some inconsistencies with the NumS version may exist.

Equivalent to nps.sinh(x)/nps.cosh(x) or -1j * nps.tan(1j*x).get().

Parameters
  • x (BlockArray) – Input array.

  • out (BlockArray, None, or 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. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.

  • where (BlockArray, optional) – This 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. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.

  • **kwargs – For other keyword-only arguments, see the ufunc docs.

Returns

y – The corresponding hyperbolic tangent values.

Return type

BlockArray

Notes

If out is provided, the function writes the result into it, and returns a reference to out. (See Examples)

References

1

M. Abramowitz and I. A. Stegun, Handbook of Mathematical Functions. New York, NY: Dover, 1972, pg. 83. http://www.math.sfu.ca/~cbm/aands/

2

Wikipedia, “Hyperbolic function”, https://en.wikipedia.org/wiki/Hyperbolic_function

Examples

The doctests shown below are copied from NumPy. They won’t show the correct result until you operate get().

>>> nps.tanh(nps.array([0, nps.pi*1j, nps.pi*1j/2])).get()  
array([ 0. +0.00000000e+00j,  0. -1.22460635e-16j,  0. +1.63317787e+16j])
>>> # Example of providing the optional output parameter illustrating
>>> # that what is returned is a reference to said parameter
>>> out1 = nps.array([0], dtype='d')  
>>> out2 = nps.tanh(nps.array([0.1]), out1)  
>>> out2 is out1  
True